build_cachex("web_resp", limit: 2500),
build_cachex("emoji_packs", expiration: emoji_packs_expiration(), limit: 10),
build_cachex("failed_proxy_url", limit: 2500),
- build_cachex("deleted_urls", default_ttl: :timer.hours(24 * 30), limit: 5_000)
+ build_cachex("banned_urls", default_ttl: :timer.hours(24 * 30), limit: 5_000)
]
end
with uploader <- Keyword.fetch!(config, :uploader),
proxy_remote = Keyword.get(config, :proxy_remote, false),
{:ok, get_method} <- uploader.get_file(file),
- false <- media_is_deleted(conn, get_method) do
+ false <- media_is_banned(conn, get_method) do
get_media(conn, get_method, proxy_remote, opts)
else
_ ->
def call(conn, _opts), do: conn
- defp media_is_deleted(%{request_path: path} = _conn, {:static_dir, _}) do
- MediaProxy.in_deleted_urls(Pleroma.Web.base_url() <> path)
+ defp media_is_banned(%{request_path: path} = _conn, {:static_dir, _}) do
+ MediaProxy.in_banned_urls(Pleroma.Web.base_url() <> path)
end
- defp media_is_deleted(_, {:url, url}), do: MediaProxy.in_deleted_urls(url)
+ defp media_is_banned(_, {:url, url}), do: MediaProxy.in_banned_urls(url)
- defp media_is_deleted(_, _), do: false
+ defp media_is_banned(_, _), do: false
defp get_media(conn, {:static_dir, directory}, _, opts) do
static_opts =
def index(%{assigns: %{user: _}} = conn, params) do
cursor =
- :deleted_urls_cache
+ :banned_urls_cache
|> :ets.table([{:traverse, {:select, Cachex.Query.create(true, :key)}}])
|> :qlc.cursor()
end
def delete(%{assigns: %{user: _}, body_params: %{urls: urls}} = conn, _) do
- MediaProxy.remove_from_deleted_urls(urls)
+ MediaProxy.remove_from_banned_urls(urls)
render(conn, "index.json", urls: urls)
end
MediaProxy.Invalidation.purge(urls)
if ban do
- MediaProxy.put_in_deleted_urls(urls)
+ MediaProxy.put_in_banned_urls(urls)
end
render(conn, "index.json", urls: urls)
@base64_opts [padding: false]
- @spec in_deleted_urls(String.t()) :: boolean()
- def in_deleted_urls(url), do: elem(Cachex.exists?(:deleted_urls_cache, url(url)), 1)
+ @spec in_banned_urls(String.t()) :: boolean()
+ def in_banned_urls(url), do: elem(Cachex.exists?(:banned_urls_cache, url(url)), 1)
- def remove_from_deleted_urls(urls) when is_list(urls) do
- Cachex.execute!(:deleted_urls_cache, fn cache ->
+ def remove_from_banned_urls(urls) when is_list(urls) do
+ Cachex.execute!(:banned_urls_cache, fn cache ->
Enum.each(Invalidation.prepare_urls(urls), &Cachex.del(cache, &1))
end)
end
- def remove_from_deleted_urls(url) when is_binary(url) do
- Cachex.del(:deleted_urls_cache, url(url))
+ def remove_from_banned_urls(url) when is_binary(url) do
+ Cachex.del(:banned_urls_cache, url(url))
end
- def put_in_deleted_urls(urls) when is_list(urls) do
- Cachex.execute!(:deleted_urls_cache, fn cache ->
+ def put_in_banned_urls(urls) when is_list(urls) do
+ Cachex.execute!(:banned_urls_cache, fn cache ->
Enum.each(Invalidation.prepare_urls(urls), &Cachex.put(cache, &1, true))
end)
end
- def put_in_deleted_urls(url) when is_binary(url) do
- Cachex.put(:deleted_urls_cache, url(url), true)
+ def put_in_banned_urls(url) when is_binary(url) do
+ Cachex.put(:banned_urls_cache, url(url), true)
end
def url(url) when is_nil(url) or url == "", do: nil
with config <- Pleroma.Config.get([:media_proxy], []),
true <- Keyword.get(config, :enabled, false),
{:ok, url} <- MediaProxy.decode_url(sig64, url64),
- {_, false} <- {:in_deleted_urls, MediaProxy.in_deleted_urls(url)},
+ {_, false} <- {:in_banned_urls, MediaProxy.in_banned_urls(url)},
:ok <- filename_matches(params, conn.request_path, url) do
ReverseProxy.call(conn, url, Keyword.get(config, :proxy_opts, @default_proxy_opts))
else
- error when error in [false, {:in_deleted_urls, true}] ->
+ error when error in [false, {:in_banned_urls, true}] ->
send_resp(conn, 404, Plug.Conn.Status.reason_phrase(404))
{:error, :invalid_signature} ->
setup do: clear_config([:media_proxy])
setup do
- on_exit(fn -> Cachex.clear(:deleted_urls_cache) end)
+ on_exit(fn -> Cachex.clear(:banned_urls_cache) end)
end
setup do
describe "GET /api/pleroma/admin/media_proxy_caches" do
test "shows banned MediaProxy URLs", %{conn: conn} do
- MediaProxy.put_in_deleted_urls([
+ MediaProxy.put_in_banned_urls([
"http://localhost:4001/media/a688346.jpg",
"http://localhost:4001/media/fb1f4d.jpg"
])
- MediaProxy.put_in_deleted_urls("http://localhost:4001/media/gb1f44.jpg")
- MediaProxy.put_in_deleted_urls("http://localhost:4001/media/tb13f47.jpg")
- MediaProxy.put_in_deleted_urls("http://localhost:4001/media/wb1f46.jpg")
+ MediaProxy.put_in_banned_urls("http://localhost:4001/media/gb1f44.jpg")
+ MediaProxy.put_in_banned_urls("http://localhost:4001/media/tb13f47.jpg")
+ MediaProxy.put_in_banned_urls("http://localhost:4001/media/wb1f46.jpg")
response =
conn
describe "POST /api/pleroma/admin/media_proxy_caches/delete" do
test "deleted MediaProxy URLs from banned", %{conn: conn} do
- MediaProxy.put_in_deleted_urls([
+ MediaProxy.put_in_banned_urls([
"http://localhost:4001/media/a688346.jpg",
"http://localhost:4001/media/fb1f4d.jpg"
])
|> json_response_and_validate_schema(200)
assert response["urls"] == ["http://localhost:4001/media/a688346.jpg"]
- refute MediaProxy.in_deleted_urls("http://localhost:4001/media/a688346.jpg")
- assert MediaProxy.in_deleted_urls("http://localhost:4001/media/fb1f4d.jpg")
+ refute MediaProxy.in_banned_urls("http://localhost:4001/media/a688346.jpg")
+ assert MediaProxy.in_banned_urls("http://localhost:4001/media/fb1f4d.jpg")
end
end
assert response["urls"] == urls
- refute MediaProxy.in_deleted_urls("http://example.com/media/a688346.jpg")
- refute MediaProxy.in_deleted_urls("http://example.com/media/fb1f4d.jpg")
+ refute MediaProxy.in_banned_urls("http://example.com/media/a688346.jpg")
+ refute MediaProxy.in_banned_urls("http://example.com/media/fb1f4d.jpg")
end
end
assert response["urls"] == urls
- assert MediaProxy.in_deleted_urls("http://example.com/media/a688346.jpg")
- assert MediaProxy.in_deleted_urls("http://example.com/media/fb1f4d.jpg")
+ assert MediaProxy.in_banned_urls("http://example.com/media/a688346.jpg")
+ assert MediaProxy.in_banned_urls("http://example.com/media/fb1f4d.jpg")
end
end
end
setup do: clear_config([:media_proxy])
setup do
- on_exit(fn -> Cachex.clear(:deleted_urls_cache) end)
+ on_exit(fn -> Cachex.clear(:banned_urls_cache) end)
end
describe "Invalidation.Http" do
Config.put([Invalidation.Http], method: :purge, headers: [{"x-refresh", 1}])
image_url = "http://example.com/media/example.jpg"
- Pleroma.Web.MediaProxy.put_in_deleted_urls(image_url)
+ Pleroma.Web.MediaProxy.put_in_banned_urls(image_url)
mock(fn
%{
end)
assert capture_log(fn ->
- assert Pleroma.Web.MediaProxy.in_deleted_urls(image_url)
+ assert Pleroma.Web.MediaProxy.in_banned_urls(image_url)
assert Invalidation.purge([image_url]) == {:ok, [image_url]}
- assert Pleroma.Web.MediaProxy.in_deleted_urls(image_url)
+ assert Pleroma.Web.MediaProxy.in_banned_urls(image_url)
end) =~ "Running cache purge: [\"#{image_url}\"]"
end
end
Config.put([Invalidation.Script], script_path: "purge-nginx")
image_url = "http://example.com/media/example.jpg"
- Pleroma.Web.MediaProxy.put_in_deleted_urls(image_url)
+ Pleroma.Web.MediaProxy.put_in_banned_urls(image_url)
with_mocks [{System, [], [cmd: fn _, _ -> {"ok", 0} end]}] do
assert capture_log(fn ->
- assert Pleroma.Web.MediaProxy.in_deleted_urls(image_url)
+ assert Pleroma.Web.MediaProxy.in_banned_urls(image_url)
assert Invalidation.purge([image_url]) == {:ok, [image_url]}
- assert Pleroma.Web.MediaProxy.in_deleted_urls(image_url)
+ assert Pleroma.Web.MediaProxy.in_banned_urls(image_url)
end) =~ "Running cache purge: [\"#{image_url}\"]"
end
end
setup do: clear_config([Pleroma.Web.Endpoint, :secret_key_base])
setup do
- on_exit(fn -> Cachex.clear(:deleted_urls_cache) end)
+ on_exit(fn -> Cachex.clear(:banned_urls_cache) end)
end
test "it returns 404 when MediaProxy disabled", %{conn: conn} do
end
end
- test "it returns 404 when url contains in deleted_urls cache", %{conn: conn} do
+ test "it returns 404 when url contains in banned_urls cache", %{conn: conn} do
Config.put([:media_proxy, :enabled], true)
Config.put([Pleroma.Web.Endpoint, :secret_key_base], "00000000000")
url = Pleroma.Web.MediaProxy.encode_url("https://google.fn/test.png")
- Pleroma.Web.MediaProxy.put_in_deleted_urls("https://google.fn/test.png")
+ Pleroma.Web.MediaProxy.put_in_banned_urls("https://google.fn/test.png")
with_mock Pleroma.ReverseProxy,
call: fn _conn, _url, _opts -> %Plug.Conn{status: :success} end do