[#2497] Removed support for thumbnail_max_* params for media preview proxy

(per https://git.pleroma.social/pleroma/pleroma/-/merge_requests/2497#note_70771)
This commit is contained in:
Ivan Tashkinov 2020-09-10 21:28:07 +03:00
parent 148bc24435
commit dc4e06e199

View File

@ -9,6 +9,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do
alias Pleroma.Helpers.MediaHelper alias Pleroma.Helpers.MediaHelper
alias Pleroma.ReverseProxy alias Pleroma.ReverseProxy
alias Pleroma.Web.MediaProxy alias Pleroma.Web.MediaProxy
alias Plug.Conn
def remote(conn, %{"sig" => sig64, "url" => url64}) do def remote(conn, %{"sig" => sig64, "url" => url64}) do
with {_, true} <- {:enabled, MediaProxy.enabled?()}, with {_, true} <- {:enabled, MediaProxy.enabled?()},
@ -18,29 +19,29 @@ def remote(conn, %{"sig" => sig64, "url" => url64}) do
ReverseProxy.call(conn, url, media_proxy_opts()) ReverseProxy.call(conn, url, media_proxy_opts())
else else
{:enabled, false} -> {:enabled, false} ->
send_resp(conn, 404, Plug.Conn.Status.reason_phrase(404)) send_resp(conn, 404, Conn.Status.reason_phrase(404))
{:in_banned_urls, true} -> {:in_banned_urls, true} ->
send_resp(conn, 404, Plug.Conn.Status.reason_phrase(404)) send_resp(conn, 404, Conn.Status.reason_phrase(404))
{:error, :invalid_signature} -> {:error, :invalid_signature} ->
send_resp(conn, 403, Plug.Conn.Status.reason_phrase(403)) send_resp(conn, 403, Conn.Status.reason_phrase(403))
{:wrong_filename, filename} -> {:wrong_filename, filename} ->
redirect(conn, external: MediaProxy.build_url(sig64, url64, filename)) redirect(conn, external: MediaProxy.build_url(sig64, url64, filename))
end end
end end
def preview(conn, %{"sig" => sig64, "url" => url64}) do def preview(%Conn{} = conn, %{"sig" => sig64, "url" => url64}) do
with {_, true} <- {:enabled, MediaProxy.preview_enabled?()}, with {_, true} <- {:enabled, MediaProxy.preview_enabled?()},
{:ok, url} <- MediaProxy.decode_url(sig64, url64) do {:ok, url} <- MediaProxy.decode_url(sig64, url64) do
handle_preview(conn, url) handle_preview(conn, url)
else else
{:enabled, false} -> {:enabled, false} ->
send_resp(conn, 404, Plug.Conn.Status.reason_phrase(404)) send_resp(conn, 404, Conn.Status.reason_phrase(404))
{:error, :invalid_signature} -> {:error, :invalid_signature} ->
send_resp(conn, 403, Plug.Conn.Status.reason_phrase(403)) send_resp(conn, 403, Conn.Status.reason_phrase(403))
{:wrong_filename, filename} -> {:wrong_filename, filename} ->
redirect(conn, external: MediaProxy.build_preview_url(sig64, url64, filename)) redirect(conn, external: MediaProxy.build_preview_url(sig64, url64, filename))
@ -94,10 +95,10 @@ defp handle_preview(content_type, conn, _media_proxy_url) do
send_resp(conn, :unprocessable_entity, "Unsupported content type: #{content_type}.") send_resp(conn, :unprocessable_entity, "Unsupported content type: #{content_type}.")
end end
defp handle_png_preview(%{params: params} = conn, media_proxy_url) do defp handle_png_preview(conn, media_proxy_url) do
quality = Config.get!([:media_preview_proxy, :image_quality]) quality = Config.get!([:media_preview_proxy, :image_quality])
with {thumbnail_max_width, thumbnail_max_height} <- thumbnail_max_dimensions(params), with {thumbnail_max_width, thumbnail_max_height} <- thumbnail_max_dimensions(),
{:ok, thumbnail_binary} <- {:ok, thumbnail_binary} <-
MediaHelper.image_resize( MediaHelper.image_resize(
media_proxy_url, media_proxy_url,
@ -117,10 +118,10 @@ defp handle_png_preview(%{params: params} = conn, media_proxy_url) do
end end
end end
defp handle_jpeg_preview(%{params: params} = conn, media_proxy_url) do defp handle_jpeg_preview(conn, media_proxy_url) do
quality = Config.get!([:media_preview_proxy, :image_quality]) quality = Config.get!([:media_preview_proxy, :image_quality])
with {thumbnail_max_width, thumbnail_max_height} <- thumbnail_max_dimensions(params), with {thumbnail_max_width, thumbnail_max_height} <- thumbnail_max_dimensions(),
{:ok, thumbnail_binary} <- {:ok, thumbnail_binary} <-
MediaHelper.image_resize( MediaHelper.image_resize(
media_proxy_url, media_proxy_url,
@ -157,22 +158,11 @@ defp put_preview_response_headers(
|> put_resp_header("cache-control", ReverseProxy.default_cache_control_header()) |> put_resp_header("cache-control", ReverseProxy.default_cache_control_header())
end end
defp thumbnail_max_dimensions(params) do defp thumbnail_max_dimensions() do
config = Config.get([:media_preview_proxy], []) config = Config.get([:media_preview_proxy], [])
thumbnail_max_width = thumbnail_max_width = Keyword.fetch!(config, :thumbnail_max_width)
if w = params["thumbnail_max_width"] do thumbnail_max_height = Keyword.fetch!(config, :thumbnail_max_height)
String.to_integer(w)
else
Keyword.fetch!(config, :thumbnail_max_width)
end
thumbnail_max_height =
if h = params["thumbnail_max_height"] do
String.to_integer(h)
else
Keyword.fetch!(config, :thumbnail_max_height)
end
{thumbnail_max_width, thumbnail_max_height} {thumbnail_max_width, thumbnail_max_height}
end end