activitypub transmogrifier: rewrite non-http URLs using the object's external URL
Signed-off-by: lain <lain@soykaf.club>
This commit is contained in:
parent
68aa9a2826
commit
59a76ea464
2 changed files with 33 additions and 0 deletions
|
|
@ -210,11 +210,31 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
|||
|
||||
def prepare_outgoing(%{"type" => type} = data) do
|
||||
data = data
|
||||
|> maybe_fix_object_url
|
||||
|> Map.put("@context", "https://www.w3.org/ns/activitystreams")
|
||||
|
||||
{:ok, data}
|
||||
end
|
||||
|
||||
def maybe_fix_object_url(data) do
|
||||
if is_binary(data["object"]) and not String.starts_with?(data["object"], "http") do
|
||||
case ActivityPub.fetch_object_from_id(data["object"]) do
|
||||
{:ok, relative_object} ->
|
||||
if relative_object.data["external_url"] do
|
||||
data = data
|
||||
|> Map.put("object", relative_object.data["external_url"])
|
||||
else
|
||||
data
|
||||
end
|
||||
e ->
|
||||
Logger.error("Couldn't fetch #{data["object"]} #{inspect(e)}")
|
||||
data
|
||||
end
|
||||
else
|
||||
data
|
||||
end
|
||||
end
|
||||
|
||||
def add_hashtags(object) do
|
||||
tags = (object["tag"] || [])
|
||||
|> Enum.map fn (tag) -> %{"href" => Pleroma.Web.Endpoint.url() <> "/tags/#{tag}", "name" => "##{tag}", "type" => "Hashtag"} end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue