From 6fe062ed6c40748610e6445cec1a9878de626e23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Tue, 8 Oct 2024 23:49:12 +0200 Subject: [PATCH] Add replacement for $ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- lib/pleroma/web/activity_pub/transmogrifier.ex | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 3a0773fc4f..4ecdb19e1b 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -1020,6 +1020,7 @@ defp replace_instance_host(value, nil), do: value defp replace_instance_host(content, host) when is_binary(content) do content |> String.replace("$INSTANCE$host$", host) + |> String.replace("$INSTANCE$tld$", get_tld(host, "$INSTANCE$tld$")) end defp replace_instance_host(object, host) when is_map(object) do @@ -1031,6 +1032,14 @@ defp replace_instance_host(object, host) when is_map(object) do defp replace_instance_host(value, _), do: value + defp get_tld(host, default) do + with [domain | _] <- String.split(host, ".") |> Enum.reverse() do + domain + else + _ -> default + end + end + defp patch_content_map(%{"contentMap" => %{} = content_map}, host) do content_map |> Enum.map(fn {key, value} -> {key, replace_instance_host(value, host)} end)