summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Felder <feld@FreeBSD.org>2020-06-04 17:26:11 -0500
committerMark Felder <feld@FreeBSD.org>2020-06-04 17:26:11 -0500
commit9d2c2a83a4f405ea36ef45144dcad972e2234a23 (patch)
tree9b0904c563436a571fc7ea769c1592eddc5d7c85
parent03369b5c4a2c91b26059240cfa076da4885e86e7 (diff)
Do not insert cache invalidations for URLs that bypass MediaProxy
-rw-r--r--lib/pleroma/web/media_proxy/invalidation.ex1
-rw-r--r--lib/pleroma/web/media_proxy/media_proxy.ex16
-rw-r--r--test/object_test.exs8
3 files changed, 19 insertions, 6 deletions
diff --git a/lib/pleroma/web/media_proxy/invalidation.ex b/lib/pleroma/web/media_proxy/invalidation.ex
index fac731c5c..537cb76d6 100644
--- a/lib/pleroma/web/media_proxy/invalidation.ex
+++ b/lib/pleroma/web/media_proxy/invalidation.ex
@@ -31,6 +31,7 @@ defmodule Pleroma.Web.MediaProxy.Invalidation do
def prepare_urls(urls) do
urls
|> List.wrap()
+ |> Enum.filter(&MediaProxy.is_url_proxiable?(&1))
|> Enum.map(&MediaProxy.url(&1))
end
end
diff --git a/lib/pleroma/web/media_proxy/media_proxy.ex b/lib/pleroma/web/media_proxy/media_proxy.ex
index 7b8e7e823..e5f1d242e 100644
--- a/lib/pleroma/web/media_proxy/media_proxy.ex
+++ b/lib/pleroma/web/media_proxy/media_proxy.ex
@@ -30,20 +30,32 @@ defmodule Pleroma.Web.MediaProxy do
end
def put_in_deleted_urls(url) when is_binary(url) do
- Cachex.put(:deleted_urls_cache, url(url), true)
+ if is_url_proxiable?(url) do
+ Cachex.put(:deleted_urls_cache, url(url), true)
+ else
+ true
+ end
end
def url(url) when is_nil(url) or url == "", do: nil
def url("/" <> _ = url), do: url
def url(url) do
- if disabled?() or local?(url) or whitelisted?(url) do
+ if disabled?() or not is_url_proxiable?(url) do
url
else
encode_url(url)
end
end
+ def is_url_proxiable?(url) do
+ if local?(url) or whitelisted?(url) do
+ false
+ else
+ true
+ end
+ end
+
defp disabled?, do: !Config.get([:media_proxy, :enabled], false)
defp local?(url), do: String.starts_with?(url, Pleroma.Web.base_url())
diff --git a/test/object_test.exs b/test/object_test.exs
index ca9f918ef..5cd2d2c80 100644
--- a/test/object_test.exs
+++ b/test/object_test.exs
@@ -149,7 +149,7 @@ defmodule Pleroma.ObjectTest do
assert Object.get_by_id(attachment.id) == nil
assert {:ok, []} == File.ls("#{uploads_dir}/#{path}")
- assert Pleroma.Web.MediaProxy.in_deleted_urls(href)
+ refute Pleroma.Web.MediaProxy.in_deleted_urls(href)
end
test "with dedupe enabled" do
@@ -190,7 +190,7 @@ defmodule Pleroma.ObjectTest do
assert Object.get_by_id(attachment.id) == nil
assert {:ok, files} = File.ls(uploads_dir)
refute filename in files
- assert Pleroma.Web.MediaProxy.in_deleted_urls(href)
+ refute Pleroma.Web.MediaProxy.in_deleted_urls(href)
end
test "with objects that have legacy data.url attribute" do
@@ -229,7 +229,7 @@ defmodule Pleroma.ObjectTest do
assert Object.get_by_id(attachment.id) == nil
assert {:ok, []} == File.ls("#{uploads_dir}/#{path}")
- assert Pleroma.Web.MediaProxy.in_deleted_urls(href)
+ refute Pleroma.Web.MediaProxy.in_deleted_urls(href)
end
test "With custom base_url" do
@@ -267,7 +267,7 @@ defmodule Pleroma.ObjectTest do
assert Object.get_by_id(attachment.id) == nil
assert {:ok, []} == File.ls("#{uploads_dir}/#{path}")
- assert Pleroma.Web.MediaProxy.in_deleted_urls(href)
+ refute Pleroma.Web.MediaProxy.in_deleted_urls(href)
end
end