Improve backup urls
authorEgor Kislitsyn <egor@kislitsyn.com>
Wed, 9 Sep 2020 16:02:20 +0000 (20:02 +0400)
committerEgor Kislitsyn <egor@kislitsyn.com>
Wed, 7 Oct 2020 14:34:29 +0000 (18:34 +0400)
lib/pleroma/web/api_spec/operations/pleroma_backup_operation.ex
lib/pleroma/web/pleroma_api/views/backup_view.ex
test/web/pleroma_api/controllers/backup_controller_test.exs

index f877ca31bb90facad8cb1cb63fe9bb274717e37f..6993794db839171cd24be19403a6dd5998321e05 100644 (file)
@@ -69,9 +69,9 @@ defmodule Pleroma.Web.ApiSpec.PleromaBackupOperation 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
       }
     }
index 02b94ce4f7f7779e1b814e9fd9b471a4d8492dcb..bf40a001e962ef295127fd39c59bb40e8f02d03b 100644 (file)
@@ -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 @@ defmodule Pleroma.Web.PleromaAPI.BackupView 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
index 1ad1b63c479f380f464c750d68efe26603ce5cba..5d2f1206e6ca3b7a756645cf47eabbf9c0889e46 100644 (file)
@@ -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 @@ defmodule Pleroma.Web.PleromaAPI.BackupControllerTest 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 @@ defmodule Pleroma.Web.PleromaAPI.BackupControllerTest do
     assert [
              %{
                "content_type" => "application/zip",
-               "file_name" => file_name,
+               "url" => url,
                "file_size" => 0,
                "processed" => false,
                "inserted_at" => _
@@ -66,7 +67,7 @@ defmodule Pleroma.Web.PleromaAPI.BackupControllerTest do
 
     assert [
              %{
-               "file_name" => ^file_name,
+               "url" => ^url,
                "processed" => true
              }
            ] =