Fix URL generated for backup files, try to create a source of truth we can reuse throughout the codebase

This commit is contained in:
Mark Felder 2021-01-07 18:34:30 -06:00
parent 5822338f3a
commit ad79983614
2 changed files with 27 additions and 1 deletions

View file

@ -31,6 +31,7 @@ defmodule Pleroma.Upload do
""" """
alias Ecto.UUID alias Ecto.UUID
alias Pleroma.Config
require Logger require Logger
@type source :: @type source ::
@ -228,4 +229,29 @@ defmodule Pleroma.Upload do
end end
defp url_from_spec(_upload, _base_url, {:url, url}), do: url 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 end

View file

@ -24,6 +24,6 @@ defmodule Pleroma.Web.PleromaAPI.BackupView do
end end
def download_url(%Backup{file_name: file_name}) do 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
end end