Use WhatsApp user-agent for rich media by default

Related https://gitlab.com/soapbox-pub/rebased/-/issues/180
This commit is contained in:
Alex Gleason 2023-01-21 16:48:51 -06:00
parent 0d08f049e9
commit e8f414b3d0
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
3 changed files with 20 additions and 1 deletions

View file

@ -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.

View file

@ -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"

View file

@ -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