From: Mark Felder Date: Fri, 8 Jan 2021 00:34:30 +0000 (-0600) Subject: Fix URL generated for backup files, try to create a source of truth we can reuse... X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=ad7998361498b08d45ea0971f8b6ecbd8ca0740e;p=akkoma Fix URL generated for backup files, try to create a source of truth we can reuse throughout the codebase --- diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex index db2cc1dae..101cfec98 100644 --- a/lib/pleroma/upload.ex +++ b/lib/pleroma/upload.ex @@ -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 diff --git a/lib/pleroma/web/pleroma_api/views/backup_view.ex b/lib/pleroma/web/pleroma_api/views/backup_view.ex index 39affe979..e04c8fc0f 100644 --- a/lib/pleroma/web/pleroma_api/views/backup_view.ex +++ b/lib/pleroma/web/pleroma_api/views/backup_view.ex @@ -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