Improve backup urls
This commit is contained in:
parent
2c73bfe122
commit
86ce4afd93
|
@ -69,9 +69,9 @@ defp backup do
|
|||
example: %{
|
||||
"content_type" => "application/zip",
|
||||
"file_name" =>
|
||||
"archive-cofe-20200908T195819-1lWrJyJqpsj8-KuHFr7N03lfsYYa5nf2NL-7A9-ddFU.zip",
|
||||
"file_size" => 1024,
|
||||
"inserted_at" => "2020-09-08T19:58:20",
|
||||
"https://cofe.fe:4000/media/backups/archive-foobar-20200908T164207-Yr7vuT5Wycv-sN3kSN2iJ0k-9pMo60j9qmvRCdDqIew.zip",
|
||||
"file_size" => 4105,
|
||||
"inserted_at" => "2020-09-08T16:42:07.000Z",
|
||||
"processed" => true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ defmodule Pleroma.Web.PleromaAPI.BackupView do
|
|||
def render("show.json", %{backup: %Backup{} = backup}) do
|
||||
%{
|
||||
content_type: backup.content_type,
|
||||
file_name: backup.file_name,
|
||||
url: download_url(backup),
|
||||
file_size: backup.file_size,
|
||||
processed: backup.processed,
|
||||
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
|
||||
render_many(backups, __MODULE__, "show.json")
|
||||
end
|
||||
|
||||
def download_url(%Backup{file_name: file_name}) do
|
||||
Pleroma.Web.Endpoint.url() <> "/media/backups/" <> file_name
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,6 +6,7 @@ defmodule Pleroma.Web.PleromaAPI.BackupControllerTest do
|
|||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Backup
|
||||
alias Pleroma.Web.PleromaAPI.BackupView
|
||||
|
||||
setup do
|
||||
clear_config([Pleroma.Upload, :uploader])
|
||||
|
@ -26,20 +27,20 @@ test "GET /api/pleroma/backups", %{user: user, conn: conn} do
|
|||
assert [
|
||||
%{
|
||||
"content_type" => "application/zip",
|
||||
"file_name" => file_name,
|
||||
"url" => url,
|
||||
"file_size" => 0,
|
||||
"processed" => false,
|
||||
"inserted_at" => _
|
||||
}
|
||||
] = response
|
||||
|
||||
assert file_name == backup.file_name
|
||||
assert url == BackupView.download_url(backup)
|
||||
|
||||
Pleroma.Tests.ObanHelpers.perform_all()
|
||||
|
||||
assert [
|
||||
%{
|
||||
"file_name" => ^file_name,
|
||||
"url" => ^url,
|
||||
"processed" => true
|
||||
}
|
||||
] =
|
||||
|
@ -52,7 +53,7 @@ test "POST /api/pleroma/backups", %{user: _user, conn: conn} do
|
|||
assert [
|
||||
%{
|
||||
"content_type" => "application/zip",
|
||||
"file_name" => file_name,
|
||||
"url" => url,
|
||||
"file_size" => 0,
|
||||
"processed" => false,
|
||||
"inserted_at" => _
|
||||
|
@ -66,7 +67,7 @@ test "POST /api/pleroma/backups", %{user: _user, conn: conn} do
|
|||
|
||||
assert [
|
||||
%{
|
||||
"file_name" => ^file_name,
|
||||
"url" => ^url,
|
||||
"processed" => true
|
||||
}
|
||||
] =
|
||||
|
|
Loading…
Reference in New Issue