diff --git a/CHANGELOG_soapbox.md b/CHANGELOG_soapbox.md index e76bf8a77f..653aa696e1 100644 --- a/CHANGELOG_soapbox.md +++ b/CHANGELOG_soapbox.md @@ -6,6 +6,11 @@ For changes to Pleroma, see `CHANGELOG.md` The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## Unreleased + +### Fixed +- Link previews not working for some websites. Let rich media user-agent be configurable (with `:pleroma, :rich_media, user_agent: "whatever"`). + ## [3.0.0] - 2022-05-24 Based on Pleroma 2.4 develop. diff --git a/config/soapbox.exs b/config/soapbox.exs index 7a0cbc0c57..049fec171b 100644 --- a/config/soapbox.exs +++ b/config/soapbox.exs @@ -53,3 +53,6 @@ # Background migration performance config :pleroma, :delete_context_objects, sleep_interval_ms: 3_000 + +# Pretend to be WhatsApp because some sites don't return link previews otherwise +config :pleroma, :rich_media, user_agent: "WhatsApp/2" diff --git a/lib/pleroma/web/rich_media/helpers.ex b/lib/pleroma/web/rich_media/helpers.ex index fde2a472cb..9e3a88a82d 100644 --- a/lib/pleroma/web/rich_media/helpers.ex +++ b/lib/pleroma/web/rich_media/helpers.ex @@ -16,7 +16,18 @@ defmodule Pleroma.Web.RichMedia.Helpers do recv_timeout: 2_000 ] - defp headers, do: [{"user-agent", Pleroma.Application.user_agent() <> "; Bot"}] + defp headers do + user_agent = + case Config.get([:rich_media, :user_agent], :default) do + :default -> + Pleroma.Application.user_agent() <> "; Bot" + + custom -> + custom + end + + [{"user-agent", user_agent}] + end @spec validate_page_url(URI.t() | binary()) :: :ok | :error defp validate_page_url(page_url) when is_binary(page_url) do