Merge branch 'media-preview-proxy' of git.pleroma.social:pleroma/pleroma into feld-media-preview-proxy

This commit is contained in:
Mark Felder 2020-09-03 14:48:43 -05:00
commit d1e1057e22
4 changed files with 20 additions and 11 deletions

View file

@ -15,6 +15,7 @@ defmodule Pleroma.Helpers.UriHelper do
uri uri
|> Map.put(:query, URI.encode_query(updated_params)) |> Map.put(:query, URI.encode_query(updated_params))
|> URI.to_string() |> URI.to_string()
|> String.replace_suffix("?", "")
end end
def maybe_add_base("/" <> uri, base), do: Path.join([base, uri]) def maybe_add_base("/" <> uri, base), do: Path.join([base, uri])

View file

@ -182,9 +182,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
display_name = user.name || user.nickname display_name = user.name || user.nickname
avatar = User.avatar_url(user) |> MediaProxy.url() avatar = User.avatar_url(user) |> MediaProxy.url()
avatar_static = User.avatar_url(user) |> MediaProxy.preview_url() avatar_static = User.avatar_url(user) |> MediaProxy.preview_url(output_format: "jpeg")
header = User.banner_url(user) |> MediaProxy.url() header = User.banner_url(user) |> MediaProxy.url()
header_static = User.banner_url(user) |> MediaProxy.preview_url() header_static = User.banner_url(user) |> MediaProxy.preview_url(output_format: "jpeg")
following_count = following_count =
if !user.hide_follows_count or !user.hide_follows or opts[:for] == user do if !user.hide_follows_count or !user.hide_follows or opts[:for] == user do

View file

@ -4,6 +4,7 @@
defmodule Pleroma.Web.MediaProxy do defmodule Pleroma.Web.MediaProxy do
alias Pleroma.Config alias Pleroma.Config
alias Pleroma.Helpers.UriHelper
alias Pleroma.Upload alias Pleroma.Upload
alias Pleroma.Web alias Pleroma.Web
alias Pleroma.Web.MediaProxy.Invalidation alias Pleroma.Web.MediaProxy.Invalidation
@ -58,9 +59,9 @@ defmodule Pleroma.Web.MediaProxy do
# Note: routing all URLs to preview handler (even local and whitelisted). # Note: routing all URLs to preview handler (even local and whitelisted).
# Preview handler will call url/1 on decoded URLs, and applicable ones will detour media proxy. # Preview handler will call url/1 on decoded URLs, and applicable ones will detour media proxy.
def preview_url(url) do def preview_url(url, preview_params \\ []) do
if preview_enabled?() do if preview_enabled?() do
encode_preview_url(url) encode_preview_url(url, preview_params)
else else
url url
end end
@ -116,10 +117,10 @@ defmodule Pleroma.Web.MediaProxy do
build_url(sig64, base64, filename(url)) build_url(sig64, base64, filename(url))
end end
def encode_preview_url(url) do def encode_preview_url(url, preview_params \\ []) do
{base64, sig64} = base64_sig64(url) {base64, sig64} = base64_sig64(url)
build_preview_url(sig64, base64, filename(url)) build_preview_url(sig64, base64, filename(url), preview_params)
end end
def decode_url(sig, url) do def decode_url(sig, url) do
@ -155,8 +156,10 @@ defmodule Pleroma.Web.MediaProxy do
proxy_url("proxy", sig_base64, url_base64, filename) proxy_url("proxy", sig_base64, url_base64, filename)
end end
def build_preview_url(sig_base64, url_base64, filename \\ nil) do def build_preview_url(sig_base64, url_base64, filename \\ nil, preview_params \\ []) do
proxy_url("proxy/preview", sig_base64, url_base64, filename) uri = proxy_url("proxy/preview", sig_base64, url_base64, filename)
UriHelper.append_uri_params(uri, preview_params)
end end
def verify_request_path_and_url( def verify_request_path_and_url(

View file

@ -64,9 +64,14 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do
end end
end end
# TODO: find a workaround so avatar_static and header_static can work. defp handle_preview(
# Those only permit GIFs for animation, so we have to permit a way to "image/" <> _ = _content_type,
# allow those to get real static variants. %{params: %{"output_format" => "jpeg"}} = conn,
url
) do
handle_jpeg_preview(conn, url)
end
defp handle_preview("image/gif" = _content_type, conn, url) do defp handle_preview("image/gif" = _content_type, conn, url) do
mediaproxy_url = url |> MediaProxy.url() mediaproxy_url = url |> MediaProxy.url()