From 199747397935610d5c4232ab96c4be841116409a Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 13 May 2021 14:22:50 -0500 Subject: Rich media: have invalid Rich/Video fall back to Link --- lib/pleroma/web/rich_media/parser/card.ex | 5 +- test/fixtures/rich_media/wordpress.html | 584 +++++++++++++++++++++++ test/fixtures/rich_media/wordpress_embed.json | 1 + test/pleroma/web/rich_media/parser/card_test.exs | 46 +- 4 files changed, 623 insertions(+), 13 deletions(-) create mode 100644 test/fixtures/rich_media/wordpress.html create mode 100644 test/fixtures/rich_media/wordpress_embed.json diff --git a/lib/pleroma/web/rich_media/parser/card.ex b/lib/pleroma/web/rich_media/parser/card.ex index abae06ab9..528837614 100644 --- a/lib/pleroma/web/rich_media/parser/card.ex +++ b/lib/pleroma/web/rich_media/parser/card.ex @@ -115,6 +115,7 @@ defmodule Pleroma.Web.RichMedia.Parser.Card do def fix_uri("http://" <> _ = uri, _base_uri), do: uri def fix_uri("https://" <> _ = uri, _base_uri), do: uri def fix_uri("/" <> _ = uri, base_uri), do: URI.merge(base_uri, uri) |> URI.to_string() + def fix_uri("", _base_uri), do: nil def fix_uri(uri, base_uri) when is_binary(uri), do: URI.merge(base_uri, "/#{uri}") |> URI.to_string() @@ -126,7 +127,9 @@ defmodule Pleroma.Web.RichMedia.Parser.Card do def validate(%Card{type: type, html: html} = card) when type in ["video", "rich"] and (is_binary(html) == false or html == "") do - {:error, {:invalid_metadata, card}} + card + |> Map.put(:type, "link") + |> validate() end def validate(%Card{type: type, title: title} = card) diff --git a/test/fixtures/rich_media/wordpress.html b/test/fixtures/rich_media/wordpress.html new file mode 100644 index 000000000..68d28e7e6 --- /dev/null +++ b/test/fixtures/rich_media/wordpress.html @@ -0,0 +1,584 @@ + + + + + + + + + + + + Mexican Drug Cartel Animation — by I Shot Him + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +
+
+
+ +
+
+ +
+
+
+
+
+
+
+ +
+
+
+

Look what you did ya li'l turd!

+
+ Everyone knows Internet Explorer turns the internet into a steaming hot pile of smelly poo poo. +
+ +
+
+
+
+
+ +
+
+
+
+
+ +
+ +
+
+ +
+ +
+

Mexican Drug Cartels

+

We collaborated with the folks at Visual.ly on this informative animation about the violence from drug cartels happening right across our border. We researched, wrote, illustrated, and animated this piece to inform people about the connections of our drug and gun laws to the death of innocents in Mexico.

+ +
+
+
+
+
+

Sharing is Caring

+ push one of these totally not dorky buttons and we will owe you one. + +
+
+
+
+ +
+ +
+ +

+

Animation

+

Mexican Cartel Animation - by I Shot Him

+

Title Screen

+

Cartel_storyboard

+

Beheadings

+

Cartel_storyboard

+

Cartel Member

+

Cartel_storyboard

+

Death Toll

+

Cartel_storyboard

+

Mass Grave

+

Cartel_storyboard

+

Death toll of police officers

+

Cartel_storyboard

+

Molotov cocktail used to burn down houses

+

Cartel_storyboard

+

We do a bunch of drugs

+

Cartel_storyboard

+

Obama needs to step up and change gun laws and drug laws

+
+ +
+

Sharing is Caring

+ push one of these totally not dorky buttons and we will owe you one. + +
+ + + + +
+ + + +
+ + +
+
+ +
+
+ + + + + +
+
+
+
+
+
+ +
+
+
+

Internet Explorer?

+
+ Unfortunately IE doesn't do a very good job of displaying the internet. +
+ +
+
+ + + + + + + + + + + + + + + diff --git a/test/fixtures/rich_media/wordpress_embed.json b/test/fixtures/rich_media/wordpress_embed.json new file mode 100644 index 000000000..51cd6c3c1 --- /dev/null +++ b/test/fixtures/rich_media/wordpress_embed.json @@ -0,0 +1 @@ +{"version":"1.0","provider_name":"I Shot Him","provider_url":"https:\/\/ishothim.com","author_name":"Michael Jeter","author_url":"https:\/\/ishothim.com\/author\/mike\/","title":"Mexican Drug Cartels","type":"rich","width":600,"height":338,"html":"
Mexican Drug Cartels<\/a><\/blockquote>\n