Skip to content

Commit

Permalink
Add replacement for $
Browse files Browse the repository at this point in the history
Signed-off-by: marcin mikołajczak <[email protected]>
  • Loading branch information
mkljczk committed Oct 8, 2024
1 parent 84b4368 commit 6fe062e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/pleroma/web/activity_pub/transmogrifier.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
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
Expand All @@ -1031,6 +1032,14 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier 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)
Expand Down

0 comments on commit 6fe062e

Please sign in to comment.