1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.PleromaAPI.BackupView do
8 alias Pleroma.User.Backup
9 alias Pleroma.Web.CommonAPI.Utils
11 def render("show.json", %{backup: %Backup{} = backup}) do
12 # To deal with records before the migration
14 if backup.state == :invalid do
15 if backup.processed, do: :complete, else: :failed
22 content_type: backup.content_type,
23 url: download_url(backup),
24 file_size: backup.file_size,
25 processed: backup.processed,
26 state: to_string(state),
27 processed_number: backup.processed_number,
28 inserted_at: Utils.to_masto_date(backup.inserted_at)
32 def render("index.json", %{backups: backups}) do
33 render_many(backups, __MODULE__, "show.json")
36 def download_url(%Backup{file_name: file_name}) do
37 Pleroma.Upload.base_url() <> "/backups/" <> file_name