Improve backup urls

This commit is contained in:
Egor Kislitsyn 2020-09-09 20:02:20 +04:00
parent 2c73bfe122
commit 86ce4afd93
No known key found for this signature in database
GPG Key ID: 1B49CB15B71E7805
3 changed files with 14 additions and 9 deletions

View File

@ -69,9 +69,9 @@ defp backup do
example: %{ example: %{
"content_type" => "application/zip", "content_type" => "application/zip",
"file_name" => "file_name" =>
"archive-cofe-20200908T195819-1lWrJyJqpsj8-KuHFr7N03lfsYYa5nf2NL-7A9-ddFU.zip", "https://cofe.fe:4000/media/backups/archive-foobar-20200908T164207-Yr7vuT5Wycv-sN3kSN2iJ0k-9pMo60j9qmvRCdDqIew.zip",
"file_size" => 1024, "file_size" => 4105,
"inserted_at" => "2020-09-08T19:58:20", "inserted_at" => "2020-09-08T16:42:07.000Z",
"processed" => true "processed" => true
} }
} }

View File

@ -11,7 +11,7 @@ defmodule Pleroma.Web.PleromaAPI.BackupView do
def render("show.json", %{backup: %Backup{} = backup}) do def render("show.json", %{backup: %Backup{} = backup}) do
%{ %{
content_type: backup.content_type, content_type: backup.content_type,
file_name: backup.file_name, url: download_url(backup),
file_size: backup.file_size, file_size: backup.file_size,
processed: backup.processed, processed: backup.processed,
inserted_at: Utils.to_masto_date(backup.inserted_at) inserted_at: Utils.to_masto_date(backup.inserted_at)
@ -21,4 +21,8 @@ def render("show.json", %{backup: %Backup{} = backup}) do
def render("index.json", %{backups: backups}) do def render("index.json", %{backups: backups}) do
render_many(backups, __MODULE__, "show.json") render_many(backups, __MODULE__, "show.json")
end end
def download_url(%Backup{file_name: file_name}) do
Pleroma.Web.Endpoint.url() <> "/media/backups/" <> file_name
end
end end

View File

@ -6,6 +6,7 @@ defmodule Pleroma.Web.PleromaAPI.BackupControllerTest do
use Pleroma.Web.ConnCase use Pleroma.Web.ConnCase
alias Pleroma.Backup alias Pleroma.Backup
alias Pleroma.Web.PleromaAPI.BackupView
setup do setup do
clear_config([Pleroma.Upload, :uploader]) clear_config([Pleroma.Upload, :uploader])
@ -26,20 +27,20 @@ test "GET /api/pleroma/backups", %{user: user, conn: conn} do
assert [ assert [
%{ %{
"content_type" => "application/zip", "content_type" => "application/zip",
"file_name" => file_name, "url" => url,
"file_size" => 0, "file_size" => 0,
"processed" => false, "processed" => false,
"inserted_at" => _ "inserted_at" => _
} }
] = response ] = response
assert file_name == backup.file_name assert url == BackupView.download_url(backup)
Pleroma.Tests.ObanHelpers.perform_all() Pleroma.Tests.ObanHelpers.perform_all()
assert [ assert [
%{ %{
"file_name" => ^file_name, "url" => ^url,
"processed" => true "processed" => true
} }
] = ] =
@ -52,7 +53,7 @@ test "POST /api/pleroma/backups", %{user: _user, conn: conn} do
assert [ assert [
%{ %{
"content_type" => "application/zip", "content_type" => "application/zip",
"file_name" => file_name, "url" => url,
"file_size" => 0, "file_size" => 0,
"processed" => false, "processed" => false,
"inserted_at" => _ "inserted_at" => _
@ -66,7 +67,7 @@ test "POST /api/pleroma/backups", %{user: _user, conn: conn} do
assert [ assert [
%{ %{
"file_name" => ^file_name, "url" => ^url,
"processed" => true "processed" => true
} }
] = ] =