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 Pleroma.Config
require Logger
@type source ::
@ -228,4 +229,29 @@ defp url_from_spec(%__MODULE__{name: name}, base_url, {:file, path}) 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

View File

@ -24,6 +24,6 @@ def render("index.json", %{backups: backups}) 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