spc-pleroma/lib/pleroma/web/pleroma_api/views/backup_view.ex

40 lines
1.1 KiB
Elixir
Raw Permalink Normal View History

2020-09-08 21:04:00 +00:00
# Pleroma: A lightweight social networking server
2022-02-26 06:11:42 +00:00
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
2020-09-08 21:04:00 +00:00
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.BackupView do
use Pleroma.Web, :view
alias Pleroma.User.Backup
2020-09-08 21:04:00 +00:00
alias Pleroma.Web.CommonAPI.Utils
def render("show.json", %{backup: %Backup{} = backup}) do
2022-12-16 19:10:48 +00:00
# To deal with records before the migration
state =
2022-12-16 19:29:21 +00:00
if backup.state == :invalid do
if backup.processed, do: :complete, else: :failed
else
backup.state
end
2022-12-16 19:10:48 +00:00
2020-09-08 21:04:00 +00:00
%{
2021-01-07 19:06:22 +00:00
id: backup.id,
2020-09-08 21:04:00 +00:00
content_type: backup.content_type,
2020-09-09 16:02:20 +00:00
url: download_url(backup),
2020-09-08 21:04:00 +00:00
file_size: backup.file_size,
processed: backup.processed,
2022-12-16 19:10:48 +00:00
state: to_string(state),
processed_number: backup.processed_number,
2020-09-08 21:04:00 +00:00
inserted_at: Utils.to_masto_date(backup.inserted_at)
}
end
def render("index.json", %{backups: backups}) do
render_many(backups, __MODULE__, "show.json")
end
2020-09-09 16:02:20 +00:00
def download_url(%Backup{file_name: file_name}) do
Pleroma.Upload.base_url() <> "/backups/" <> file_name
2020-09-09 16:02:20 +00:00
end
2020-09-08 21:04:00 +00:00
end