- Renamed `:timeout` in `pools` namespace to `:recv_timeout`, old name is deprecated.
- Minimum lifetime for ephmeral activities changed to 10 minutes and made configurable (`:min_lifetime` option).
+### Added
+- Media preview proxy (requires media proxy be enabled; see `:media_preview_proxy` config for more details).
+
### Removed
- **Breaking:** `Pleroma.Workers.Cron.StatsWorker` setting from Oban `:crontab` (moved to a simpler implementation).
alias Pleroma.HTTP
- @tmp_base "/tmp/pleroma-media_preview-pipe"
-
def image_resize(url, options) do
with executable when is_binary(executable) <- System.find_executable("convert"),
{:ok, args} <- prepare_image_resize_args(options),
end
defp mkfifo do
- path = "#{@tmp_base}#{to_charlist(:erlang.phash2(self()))}"
+ path = Path.join(System.tmp_dir!(), "pleroma-media-preview-pipe-#{Ecto.UUID.generate()}")
case System.cmd("mkfifo", [path]) do
{_, 0} ->
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Helpers.UriHelper do
- def append_uri_params(uri, appended_params) do
+ def modify_uri_params(uri, overridden_params, deleted_params \\ []) do
uri = URI.parse(uri)
- appended_params = for {k, v} <- appended_params, into: %{}, do: {to_string(k), v}
- existing_params = URI.query_decoder(uri.query || "") |> Enum.into(%{})
- updated_params_keys = Enum.uniq(Map.keys(existing_params) ++ Map.keys(appended_params))
+
+ existing_params = URI.query_decoder(uri.query || "") |> Map.new()
+ overridden_params = Map.new(overridden_params, fn {k, v} -> {to_string(k), v} end)
+ deleted_params = Enum.map(deleted_params, &to_string/1)
updated_params =
- for k <- updated_params_keys, do: {k, appended_params[k] || existing_params[k]}
+ existing_params
+ |> Map.merge(overridden_params)
+ |> Map.drop(deleted_params)
uri
|> Map.put(:query, URI.encode_query(updated_params))
display_name = user.name || user.nickname
avatar = User.avatar_url(user) |> MediaProxy.url()
- avatar_static = User.avatar_url(user) |> MediaProxy.preview_url(output_format: "jpeg")
+ avatar_static = User.avatar_url(user) |> MediaProxy.preview_url(static: true)
header = User.banner_url(user) |> MediaProxy.url()
- header_static = User.banner_url(user) |> MediaProxy.preview_url(output_format: "jpeg")
+ header_static = User.banner_url(user) |> MediaProxy.preview_url(static: true)
following_count =
if !user.hide_follows_count or !user.hide_follows or opts[:for] == user do
def build_preview_url(sig_base64, url_base64, filename \\ nil, preview_params \\ []) do
uri = proxy_url("proxy/preview", sig_base64, url_base64, filename)
- UriHelper.append_uri_params(uri, preview_params)
+ UriHelper.modify_uri_params(uri, preview_params)
end
def verify_request_path_and_url(
alias Pleroma.Config
alias Pleroma.Helpers.MediaHelper
+ alias Pleroma.Helpers.UriHelper
alias Pleroma.ReverseProxy
alias Pleroma.Web.MediaProxy
alias Plug.Conn
end
defp handle_preview(
- "image/" <> _ = _content_type,
+ "image/gif" = _content_type,
_content_length,
- %{params: %{"output_format" => "jpeg"}} = conn,
+ %{params: %{"static" => static}} = conn,
media_proxy_url
- ) do
+ )
+ when static in ["true", true] do
handle_jpeg_preview(conn, media_proxy_url)
end
+ defp handle_preview(
+ _content_type,
+ _content_length,
+ %{params: %{"static" => static}} = conn,
+ _media_proxy_url
+ )
+ when static in ["true", true] do
+ uri_without_static_param = UriHelper.modify_uri_params(current_url(conn), %{}, ["static"])
+ redirect(conn, external: uri_without_static_param)
+ end
+
defp handle_preview("image/gif" = _content_type, _content_length, conn, media_proxy_url) do
redirect(conn, external: media_proxy_url)
end
redirect_uri = redirect_uri(conn, redirect_uri)
url_params = %{access_token: token.token}
url_params = Maps.put_if_present(url_params, :state, params["state"])
- url = UriHelper.append_uri_params(redirect_uri, url_params)
+ url = UriHelper.modify_uri_params(redirect_uri, url_params)
redirect(conn, external: url)
else
conn
redirect_uri = redirect_uri(conn, redirect_uri)
url_params = %{code: auth.token}
url_params = Maps.put_if_present(url_params, :state, auth_attrs["state"])
- url = UriHelper.append_uri_params(redirect_uri, url_params)
+ url = UriHelper.modify_uri_params(redirect_uri, url_params)
redirect(conn, external: url)
else
conn