Fix URL generated for backup files, try to create a source of truth we can reuse...
authorMark Felder <feld@feld.me>
Fri, 8 Jan 2021 00:34:30 +0000 (18:34 -0600)
committerMark Felder <feld@feld.me>
Fri, 8 Jan 2021 23:32:42 +0000 (17:32 -0600)
lib/pleroma/upload.ex
lib/pleroma/web/pleroma_api/views/backup_view.ex

index db2cc1dae278009701222528e3bd159a7b7a494e..101cfec983bbcb9bcd6930b2d2ea8bb0afb141e3 100644 (file)
@@ -31,6 +31,7 @@ defmodule Pleroma.Upload do
 
   """
   alias Ecto.UUID
+  alias Pleroma.Config
   require Logger
 
   @type source ::
@@ -228,4 +229,29 @@ defmodule Pleroma.Upload do
   end
 
   defp url_from_spec(_upload, _base_url, {:url, url}), do: url
+
+  def base_url do
+    uploader = Config.get([Pleroma.Upload, :uploader])
+    upload_base_url = Config.get([Pleroma.Upload, :base_url])
+
+    case uploader do
+      Pleroma.Uploaders.Local ->
+        cond do
+          !is_nil(upload_base_url) ->
+            upload_base_url
+
+          true ->
+            Pleroma.Web.base_url() <> "/media/"
+        end
+
+      _ ->
+        cond do
+          !is_nil(Config.get([uploader, :public_endpoint])) ->
+            Config.get([uploader, :public_endpoint])
+
+          true ->
+            upload_base_url
+        end
+    end
+  end
 end
index 39affe9793abd87ea255f8008569a3de4c9fc9db..e04c8fc0f1cab10c4dcc1bef7e878d2e92e0a85b 100644 (file)
@@ -24,6 +24,6 @@ defmodule Pleroma.Web.PleromaAPI.BackupView do
   end
 
   def download_url(%Backup{file_name: file_name}) do
-    Pleroma.Web.Endpoint.url() <> "/media/backups/" <> file_name
+    Pleroma.Upload.base_url() <> "/backups/" <> file_name
   end
 end