More places we should be using Upload.base_url
authorMark Felder <feld@feld.me>
Fri, 8 Jan 2021 23:05:55 +0000 (17:05 -0600)
committerMark Felder <feld@feld.me>
Fri, 8 Jan 2021 23:32:42 +0000 (17:32 -0600)
lib/pleroma/web/media_proxy.ex
lib/pleroma/web/plugs/uploaded_media.ex
lib/pleroma/workers/attachments_cleanup_worker.ex

index 2793cabc1d405ed3bbe00730168f566a37e9b744..95e3f4231a5cfd42666def30aec1511a7080325b 100644 (file)
@@ -69,7 +69,7 @@ defmodule Pleroma.Web.MediaProxy do
   #   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 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
     %{host: domain} = URI.parse(url)
@@ -80,11 +80,13 @@ defmodule Pleroma.Web.MediaProxy do
       |> Enum.map(&maybe_get_domain_from_url/1)
 
     whitelist_domains =
-      if base_url = Config.get([Upload, :base_url]) do
-        %{host: base_domain} = URI.parse(base_url)
-        [base_domain | mediaproxy_whitelist_domains]
-      else
-        mediaproxy_whitelist_domains
+      cond do
+        Web.base_url() == Upload.base_url() ->
+          mediaproxy_whitelist_domains
+
+        true ->
+          %{host: base_domain} = URI.parse(Upload.base_url())
+          [base_domain | mediaproxy_whitelist_domains]
       end
 
     domain in whitelist_domains
index 94b4c2177d9ae762c5d1491c3c611ce882df95f6..175b4d87d533adca70ddb61dd546977942c636ce 100644 (file)
@@ -62,7 +62,7 @@ defmodule Pleroma.Web.Plugs.UploadedMedia do
   def call(conn, _opts), do: conn
 
   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
 
   defp media_is_banned(_, {:url, url}), do: MediaProxy.in_banned_urls(url)
index 58226b395ef21501284bbe162dae307028ca4933..69758e8c178ded88b29b7f0e753d62ddb50a75e2 100644 (file)
@@ -32,21 +32,15 @@ defmodule Pleroma.Workers.AttachmentsCleanupWorker do
   defp do_clean({object_ids, attachment_urls}) do
     uploader = Pleroma.Config.get([Pleroma.Upload, :uploader])
 
-    prefix =
-      case Pleroma.Config.get([Pleroma.Upload, :base_url]) do
-        nil -> "media"
-        _ -> ""
-      end
-
     base_url =
       String.trim_trailing(
-        Pleroma.Config.get([Pleroma.Upload, :base_url], Pleroma.Web.base_url()),
+        Pleroma.Upload.base_url(),
         "/"
       )
 
     Enum.each(attachment_urls, fn href ->
       href
-      |> String.trim_leading("#{base_url}/#{prefix}")
+      |> String.trim_leading("#{base_url}")
       |> uploader.delete_file()
     end)