2020-09-08 23:04:00 +02:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.PleromaAPI.BackupView do
|
|
|
|
use Pleroma.Web, :view
|
|
|
|
|
2020-10-20 15:16:58 +02:00
|
|
|
alias Pleroma.User.Backup
|
2020-09-08 23:04:00 +02:00
|
|
|
alias Pleroma.Web.CommonAPI.Utils
|
|
|
|
|
|
|
|
def render("show.json", %{backup: %Backup{} = backup}) do
|
|
|
|
%{
|
2021-01-07 20:06:22 +01:00
|
|
|
id: backup.id,
|
2020-09-08 23:04:00 +02:00
|
|
|
content_type: backup.content_type,
|
2020-09-09 18:02:20 +02:00
|
|
|
url: download_url(backup),
|
2020-09-08 23:04:00 +02:00
|
|
|
file_size: backup.file_size,
|
|
|
|
processed: backup.processed,
|
|
|
|
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 18:02:20 +02:00
|
|
|
|
|
|
|
def download_url(%Backup{file_name: file_name}) do
|
|
|
|
Pleroma.Web.Endpoint.url() <> "/media/backups/" <> file_name
|
|
|
|
end
|
2020-09-08 23:04:00 +02:00
|
|
|
end
|