transmogrifier: significantly rework handling of peertube videos, add test
This commit is contained in:
parent
3aff8067e4
commit
71f6d9f418
2 changed files with 56 additions and 11 deletions
|
@ -170,8 +170,14 @@ def fix_attachments(%{"attachment" => attachment} = object) when is_list(attachm
|
||||||
attachments =
|
attachments =
|
||||||
attachment
|
attachment
|
||||||
|> Enum.map(fn data ->
|
|> Enum.map(fn data ->
|
||||||
url = [%{"type" => "Link", "mediaType" => data["mediaType"], "href" => data["url"]}]
|
media_type = data["mediaType"] || data["mimeType"]
|
||||||
Map.put(data, "url", url)
|
href = data["url"] || data["href"]
|
||||||
|
|
||||||
|
url = [%{"type" => "Link", "mediaType" => media_type, "href" => href}]
|
||||||
|
|
||||||
|
data
|
||||||
|
|> Map.put("mediaType", media_type)
|
||||||
|
|> Map.put("url", url)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
object
|
object
|
||||||
|
@ -190,7 +196,22 @@ def fix_url(%{"url" => url} = object) when is_map(url) do
|
||||||
|> Map.put("url", url["href"])
|
|> Map.put("url", url["href"])
|
||||||
end
|
end
|
||||||
|
|
||||||
def fix_url(%{"url" => url} = object) when is_list(url) do
|
def fix_url(%{"type" => "Video", "url" => url} = object) when is_list(url) do
|
||||||
|
first_element = Enum.at(url, 0)
|
||||||
|
|
||||||
|
link_element =
|
||||||
|
url
|
||||||
|
|> Enum.filter(fn x -> is_map(x) end)
|
||||||
|
|> Enum.filter(fn x -> x["mimeType"] == "text/html" end)
|
||||||
|
|> Enum.at(0)
|
||||||
|
|
||||||
|
object
|
||||||
|
|> Map.put("attachment", [first_element])
|
||||||
|
|> Map.put("url", link_element["href"])
|
||||||
|
end
|
||||||
|
|
||||||
|
def fix_url(%{"type" => object_type, "url" => url} = object)
|
||||||
|
when object_type != "Video" and is_list(url) do
|
||||||
first_element = Enum.at(url, 0)
|
first_element = Enum.at(url, 0)
|
||||||
|
|
||||||
url_string =
|
url_string =
|
||||||
|
@ -200,15 +221,9 @@ def fix_url(%{"url" => url} = object) when is_list(url) do
|
||||||
true -> ""
|
true -> ""
|
||||||
end
|
end
|
||||||
|
|
||||||
if Map.get(object, "type") == "Video" do
|
|
||||||
object
|
|
||||||
|> Map.delete("url")
|
|
||||||
|> Map.put("attachment", url_string)
|
|
||||||
else
|
|
||||||
object
|
object
|
||||||
|> Map.put("url", url_string)
|
|> Map.put("url", url_string)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def fix_url(object), do: object
|
def fix_url(object), do: object
|
||||||
|
|
||||||
|
|
|
@ -684,6 +684,36 @@ test "it rejects activities without a valid ID" do
|
||||||
|
|
||||||
:error = Transmogrifier.handle_incoming(data)
|
:error = Transmogrifier.handle_incoming(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it remaps video URLs as attachments if necessary" do
|
||||||
|
{:ok, object} =
|
||||||
|
ActivityPub.fetch_object_from_id(
|
||||||
|
"https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
|
||||||
|
)
|
||||||
|
|
||||||
|
attachment = %{
|
||||||
|
"type" => "Link",
|
||||||
|
"mediaType" => "video/mp4",
|
||||||
|
"href" =>
|
||||||
|
"https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
|
||||||
|
"mimeType" => "video/mp4",
|
||||||
|
"size" => 5_015_880,
|
||||||
|
"url" => [
|
||||||
|
%{
|
||||||
|
"href" =>
|
||||||
|
"https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
|
||||||
|
"mediaType" => "video/mp4",
|
||||||
|
"type" => "Link"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"width" => 480
|
||||||
|
}
|
||||||
|
|
||||||
|
assert object.data["url"] ==
|
||||||
|
"https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
|
||||||
|
|
||||||
|
assert object.data["attachment"] == [attachment]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "prepare outgoing" do
|
describe "prepare outgoing" do
|
||||||
|
|
Loading…
Reference in a new issue