Merge remote-tracking branch 'remotes/origin/develop' into 2168-media-preview-proxy
[akkoma] / lib / pleroma / web / media_proxy / media_proxy_controller.ex
index fb4b80379e5efedf572dff563b8554ffb7000412..0f4575e2f20d0782ade5a3183074ab57d491efd5 100644 (file)
@@ -12,6 +12,7 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do
 
   def remote(conn, %{"sig" => sig64, "url" => url64}) do
     with {_, true} <- {:enabled, MediaProxy.enabled?()},
+         {_, false} <- {:in_banned_urls, MediaProxy.in_banned_urls(url)},
          {:ok, url} <- MediaProxy.decode_url(sig64, url64),
          :ok <- MediaProxy.verify_request_path_and_url(conn, url) do
       proxy_opts = Config.get([:media_proxy, :proxy_opts], [])
@@ -20,6 +21,9 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do
       {:enabled, false} ->
         send_resp(conn, 404, Plug.Conn.Status.reason_phrase(404))
 
+      {:in_banned_urls, true} ->
+        send_resp(conn, 404, Plug.Conn.Status.reason_phrase(404))
+
       {:error, :invalid_signature} ->
         send_resp(conn, 403, Plug.Conn.Status.reason_phrase(403))
 
@@ -82,17 +86,16 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do
     {thumbnail_max_width, thumbnail_max_height}
   end
 
-  defp handle_preview("image/" <> _ = content_type, %{params: params} = conn, url) do
+  defp handle_preview("image/" <> _ = _content_type, %{params: params} = conn, url) do
     with {thumbnail_max_width, thumbnail_max_height} <- thumbnail_max_dimensions(params),
          media_proxy_url <- MediaProxy.url(url),
          {:ok, thumbnail_binary} <-
            MediaHelper.ffmpeg_resize_remote(
              media_proxy_url,
-             thumbnail_max_width,
-             thumbnail_max_height
+             %{max_width: thumbnail_max_width, max_height: thumbnail_max_height}
            ) do
       conn
-      |> put_resp_header("content-type", content_type)
+      |> put_resp_header("content-type", "image/jpeg")
       |> send_resp(200, thumbnail_binary)
     else
       _ ->