diff options
author | lain <lain@soykaf.club> | 2020-07-07 09:14:50 +0000 |
---|---|---|
committer | lain <lain@soykaf.club> | 2020-07-07 09:14:50 +0000 |
commit | 9ad305209aabd8619a397060f979c1f4e735def3 (patch) | |
tree | dfa37cb5a9d1f27c13559221a6af1c57201fc9dc /lib/pleroma | |
parent | fa0fa4552f186d03abb59aba22d3f4eac1654e1e (diff) | |
parent | fbb9743a7058e8a7ace69804b79eb032e03da078 (diff) | |
download | pleroma-9ad305209aabd8619a397060f979c1f4e735def3.tar.gz |
Merge branch 'bugfix/peertube-videos' into 'develop'
Fix getting videos from peertube
See merge request pleroma/pleroma!2728
Diffstat (limited to 'lib/pleroma')
-rw-r--r-- | lib/pleroma/web/activity_pub/transmogrifier.ex | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index bc6fc4bd8..117e930b3 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -233,18 +233,24 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do is_map(url) && is_binary(url["href"]) -> url["href"] is_binary(data["url"]) -> data["url"] is_binary(data["href"]) -> data["href"] + true -> nil end - attachment_url = - %{"href" => href} - |> Maps.put_if_present("mediaType", media_type) - |> Maps.put_if_present("type", Map.get(url || %{}, "type")) + if href do + attachment_url = + %{"href" => href} + |> Maps.put_if_present("mediaType", media_type) + |> Maps.put_if_present("type", Map.get(url || %{}, "type")) - %{"url" => [attachment_url]} - |> Maps.put_if_present("mediaType", media_type) - |> Maps.put_if_present("type", data["type"]) - |> Maps.put_if_present("name", data["name"]) + %{"url" => [attachment_url]} + |> Maps.put_if_present("mediaType", media_type) + |> Maps.put_if_present("type", data["type"]) + |> Maps.put_if_present("name", data["name"]) + else + nil + end end) + |> Enum.filter(& &1) Map.put(object, "attachment", attachments) end @@ -263,12 +269,18 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do def fix_url(%{"type" => object_type, "url" => url} = object) when object_type in ["Video", "Audio"] and is_list(url) do - first_element = Enum.at(url, 0) + attachment = + Enum.find(url, fn x -> + media_type = x["mediaType"] || x["mimeType"] || "" + + is_map(x) and String.starts_with?(media_type, ["audio/", "video/"]) + end) - link_element = Enum.find(url, fn x -> is_map(x) and x["mimeType"] == "text/html" end) + link_element = + Enum.find(url, fn x -> is_map(x) and (x["mediaType"] || x["mimeType"]) == "text/html" end) object - |> Map.put("attachment", [first_element]) + |> Map.put("attachment", [attachment]) |> Map.put("url", link_element["href"]) end |