diff options
author | Haelwenn (lanodan) Monnier <contact@hacktivis.me> | 2021-02-21 23:41:13 +0100 |
---|---|---|
committer | Haelwenn (lanodan) Monnier <contact@hacktivis.me> | 2021-02-21 23:41:28 +0100 |
commit | 7fc9cd09740e31fe75ff3402f29614bb328240f7 (patch) | |
tree | bd2af94b89702e086f5281488792192c42ae78ad /lib | |
parent | 8829a408ecf3bfffaf59af415817220fd63a81b7 (diff) | |
download | pleroma-7fc9cd09740e31fe75ff3402f29614bb328240f7.tar.gz pleroma-7fc9cd09740e31fe75ff3402f29614bb328240f7.zip |
Video: Handle peertube videos only stashing attachments in x-mpegURL
Closes: https://git.pleroma.social/pleroma/pleroma/-/issues/2535
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/web/activity_pub/object_validators/audio_video_validator.ex | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/lib/pleroma/web/activity_pub/object_validators/audio_video_validator.ex b/lib/pleroma/web/activity_pub/object_validators/audio_video_validator.ex index b3e738d8d..4a96fef52 100644 --- a/lib/pleroma/web/activity_pub/object_validators/audio_video_validator.ex +++ b/lib/pleroma/web/activity_pub/object_validators/audio_video_validator.ex @@ -70,19 +70,33 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AudioVideoValidator do |> changeset(data) end - defp fix_url(%{"url" => url} = data) when is_list(url) do - attachment = - Enum.find(url, fn x -> - mime_type = x["mimeType"] || x["mediaType"] || "" - - is_map(x) and String.starts_with?(mime_type, ["video/", "audio/"]) + defp find_attachment(url) do + mpeg_url = + Enum.find(url, fn + %{"mediaType" => mime_type, "tag" => tags} when is_list(tags) -> + mime_type == "application/x-mpegURL" + + _ -> + false end) - link_element = - Enum.find(url, fn x -> - mime_type = x["mimeType"] || x["mediaType"] || "" + url + |> Enum.concat(mpeg_url["tag"] || []) + |> Enum.find(fn + %{"mediaType" => mime_type} -> String.starts_with?(mime_type, ["video/", "audio/"]) + %{"mimeType" => mime_type} -> String.starts_with?(mime_type, ["video/", "audio/"]) + _ -> false + end) + end - is_map(x) and mime_type == "text/html" + defp fix_url(%{"url" => url} = data) when is_list(url) do + attachment = find_attachment(url) + + link_element = + Enum.find(url, fn + %{"mediaType" => "text/html"} -> true + %{"mimeType" => "text/html"} -> true + _ -> false end) data |