More places we should be using Upload.base_url

This commit is contained in:
Mark Felder 2021-01-08 17:05:55 -06:00
parent 530fb5b29e
commit 86dcfb4eb9
3 changed files with 11 additions and 15 deletions

View File

@ -69,7 +69,7 @@ def enabled?, do: Config.get([:media_proxy, :enabled], false)
# non-local non-whitelisted URLs through it and be sure that body size constraint is preserved. # non-local non-whitelisted URLs through it and be sure that body size constraint is preserved.
def preview_enabled?, do: enabled?() and !!Config.get([:media_preview_proxy, :enabled]) def preview_enabled?, do: enabled?() and !!Config.get([:media_preview_proxy, :enabled])
def local?(url), do: String.starts_with?(url, Pleroma.Web.base_url()) def local?(url), do: String.starts_with?(url, Upload.base_url())
def whitelisted?(url) do def whitelisted?(url) do
%{host: domain} = URI.parse(url) %{host: domain} = URI.parse(url)
@ -80,11 +80,13 @@ def whitelisted?(url) do
|> Enum.map(&maybe_get_domain_from_url/1) |> Enum.map(&maybe_get_domain_from_url/1)
whitelist_domains = whitelist_domains =
if base_url = Config.get([Upload, :base_url]) do cond do
%{host: base_domain} = URI.parse(base_url) Web.base_url() == Upload.base_url() ->
[base_domain | mediaproxy_whitelist_domains] mediaproxy_whitelist_domains
else
mediaproxy_whitelist_domains true ->
%{host: base_domain} = URI.parse(Upload.base_url())
[base_domain | mediaproxy_whitelist_domains]
end end
domain in whitelist_domains domain in whitelist_domains

View File

@ -62,7 +62,7 @@ def call(%{request_path: <<"/", @path, "/", file::binary>>} = conn, opts) do
def call(conn, _opts), do: conn def call(conn, _opts), do: conn
defp media_is_banned(%{request_path: path} = _conn, {:static_dir, _}) do defp media_is_banned(%{request_path: path} = _conn, {:static_dir, _}) do
MediaProxy.in_banned_urls(Pleroma.Web.base_url() <> path) MediaProxy.in_banned_urls(Pleroma.Upload.base_url() <> path)
end end
defp media_is_banned(_, {:url, url}), do: MediaProxy.in_banned_urls(url) defp media_is_banned(_, {:url, url}), do: MediaProxy.in_banned_urls(url)

View File

@ -32,21 +32,15 @@ def perform(%Job{args: %{"op" => "cleanup_attachments", "object" => _object}}),
defp do_clean({object_ids, attachment_urls}) do defp do_clean({object_ids, attachment_urls}) do
uploader = Pleroma.Config.get([Pleroma.Upload, :uploader]) uploader = Pleroma.Config.get([Pleroma.Upload, :uploader])
prefix =
case Pleroma.Config.get([Pleroma.Upload, :base_url]) do
nil -> "media"
_ -> ""
end
base_url = base_url =
String.trim_trailing( String.trim_trailing(
Pleroma.Config.get([Pleroma.Upload, :base_url], Pleroma.Web.base_url()), Pleroma.Upload.base_url(),
"/" "/"
) )
Enum.each(attachment_urls, fn href -> Enum.each(attachment_urls, fn href ->
href href
|> String.trim_leading("#{base_url}/#{prefix}") |> String.trim_leading("#{base_url}")
|> uploader.delete_file() |> uploader.delete_file()
end) end)