rich media: parser: splice the given URL into the result

This commit is contained in:
Ariadne Conill 2019-07-23 22:58:31 +00:00
parent 1a751529fb
commit d3bdb8e704
4 changed files with 17 additions and 13 deletions

View File

@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- ActivityPub C2S: follower/following collection pages being inaccessible even when authentifucated if `hide_followers`/ `hide_follows` was set - ActivityPub C2S: follower/following collection pages being inaccessible even when authentifucated if `hide_followers`/ `hide_follows` was set
- Existing user id not being preserved on insert conflict - Existing user id not being preserved on insert conflict
- Rich Media: Parser failing when no TTL can be found by image TTL setters - Rich Media: Parser failing when no TTL can be found by image TTL setters
- Rich Media: The crawled URL is now spliced into the rich media data.
- ActivityPub S2S: sharedInbox usage has been mostly aligned with the rules in the AP specification. - ActivityPub S2S: sharedInbox usage has been mostly aligned with the rules in the AP specification.
### Added ### Added

View File

@ -82,6 +82,7 @@ defp parse_url(url) do
html html
|> maybe_parse() |> maybe_parse()
|> Map.put(:url, url)
|> clean_parsed_data() |> clean_parsed_data()
|> check_parsed_data() |> check_parsed_data()
rescue rescue

View File

@ -2815,11 +2815,11 @@ test "returns rich-media card", %{conn: conn, user: user} do
card_data = %{ card_data = %{
"image" => "http://ia.media-imdb.com/images/rock.jpg", "image" => "http://ia.media-imdb.com/images/rock.jpg",
"provider_name" => "www.imdb.com", "provider_name" => "example.com",
"provider_url" => "http://www.imdb.com", "provider_url" => "https://example.com",
"title" => "The Rock", "title" => "The Rock",
"type" => "link", "type" => "link",
"url" => "http://www.imdb.com/title/tt0117500/", "url" => "https://example.com/ogp",
"description" => "description" =>
"Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer.", "Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer.",
"pleroma" => %{ "pleroma" => %{
@ -2827,7 +2827,7 @@ test "returns rich-media card", %{conn: conn, user: user} do
"image" => "http://ia.media-imdb.com/images/rock.jpg", "image" => "http://ia.media-imdb.com/images/rock.jpg",
"title" => "The Rock", "title" => "The Rock",
"type" => "video.movie", "type" => "video.movie",
"url" => "http://www.imdb.com/title/tt0117500/", "url" => "https://example.com/ogp",
"description" => "description" =>
"Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer." "Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer."
} }
@ -2868,14 +2868,14 @@ test "replaces missing description with an empty string", %{conn: conn, user: us
"title" => "Pleroma", "title" => "Pleroma",
"description" => "", "description" => "",
"image" => nil, "image" => nil,
"provider_name" => "pleroma.social", "provider_name" => "example.com",
"provider_url" => "https://pleroma.social", "provider_url" => "https://example.com",
"url" => "https://pleroma.social/", "url" => "https://example.com/ogp-missing-data",
"pleroma" => %{ "pleroma" => %{
"opengraph" => %{ "opengraph" => %{
"title" => "Pleroma", "title" => "Pleroma",
"type" => "website", "type" => "website",
"url" => "https://pleroma.social/" "url" => "https://example.com/ogp-missing-data"
} }
} }
} }

View File

@ -59,7 +59,8 @@ test "returns error when no metadata present" do
test "doesn't just add a title" do test "doesn't just add a title" do
assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/non-ogp") == assert Pleroma.Web.RichMedia.Parser.parse("http://example.com/non-ogp") ==
{:error, "Found metadata was invalid or incomplete: %{}"} {:error,
"Found metadata was invalid or incomplete: %{url: \"http://example.com/non-ogp\"}"}
end end
test "parses ogp" do test "parses ogp" do
@ -71,7 +72,7 @@ test "parses ogp" do
description: description:
"Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer.", "Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer.",
type: "video.movie", type: "video.movie",
url: "http://www.imdb.com/title/tt0117500/" url: "http://example.com/ogp"
}} }}
end end
@ -84,7 +85,7 @@ test "falls back to <title> when ogp:title is missing" do
description: description:
"Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer.", "Directed by Michael Bay. With Sean Connery, Nicolas Cage, Ed Harris, John Spencer.",
type: "video.movie", type: "video.movie",
url: "http://www.imdb.com/title/tt0117500/" url: "http://example.com/ogp-missing-title"
}} }}
end end
@ -96,7 +97,8 @@ test "parses twitter card" do
site: "@flickr", site: "@flickr",
image: "https://farm6.staticflickr.com/5510/14338202952_93595258ff_z.jpg", image: "https://farm6.staticflickr.com/5510/14338202952_93595258ff_z.jpg",
title: "Small Island Developing States Photo Submission", title: "Small Island Developing States Photo Submission",
description: "View the album on Flickr." description: "View the album on Flickr.",
url: "http://example.com/twitter-card"
}} }}
end end
@ -120,7 +122,7 @@ test "parses OEmbed" do
thumbnail_width: 150, thumbnail_width: 150,
title: "Bacon Lollys", title: "Bacon Lollys",
type: "photo", type: "photo",
url: "https://farm4.staticflickr.com/3040/2362225867_4a87ab8baf_b.jpg", url: "http://example.com/oembed",
version: "1.0", version: "1.0",
web_page: "https://www.flickr.com/photos/bees/2362225867/", web_page: "https://www.flickr.com/photos/bees/2362225867/",
web_page_short_url: "https://flic.kr/p/4AK2sc", web_page_short_url: "https://flic.kr/p/4AK2sc",