mastodon api: use OGP uri instead of page_url for deducing domain name, fix test
This commit is contained in:
parent
86037e9c39
commit
1f7843b9b8
|
@ -1329,12 +1329,14 @@ def get_status_card(status_id) do
|
||||||
%Object{} = object <- Object.normalize(activity.data["object"]),
|
%Object{} = object <- Object.normalize(activity.data["object"]),
|
||||||
page_url <- HTML.extract_first_external_url(object, object.data["content"]),
|
page_url <- HTML.extract_first_external_url(object, object.data["content"]),
|
||||||
{:ok, rich_media} <- Pleroma.Web.RichMedia.Parser.parse(page_url) do
|
{:ok, rich_media} <- Pleroma.Web.RichMedia.Parser.parse(page_url) do
|
||||||
|
page_url = rich_media[:url] || page_url
|
||||||
site_name = rich_media[:site_name] || URI.parse(page_url).host
|
site_name = rich_media[:site_name] || URI.parse(page_url).host
|
||||||
|
|
||||||
rich_media
|
rich_media
|
||||||
|> Map.take([:image, :title, :url, :description])
|
|> Map.take([:image, :title, :description])
|
||||||
|> Map.put(:type, "link")
|
|> Map.put(:type, "link")
|
||||||
|> Map.put(:provider_name, site_name)
|
|> Map.put(:provider_name, site_name)
|
||||||
|
|> Map.put(:url, page_url)
|
||||||
else
|
else
|
||||||
_ -> %{}
|
_ -> %{}
|
||||||
end
|
end
|
||||||
|
|
|
@ -1634,6 +1634,7 @@ test "Status rich-media Card", %{conn: conn, user: user} do
|
||||||
|
|
||||||
assert response == %{
|
assert response == %{
|
||||||
"image" => "http://ia.media-imdb.com/images/rock.jpg",
|
"image" => "http://ia.media-imdb.com/images/rock.jpg",
|
||||||
|
"provider_name" => "www.imdb.com",
|
||||||
"title" => "The Rock",
|
"title" => "The Rock",
|
||||||
"type" => "link",
|
"type" => "link",
|
||||||
"url" => "http://www.imdb.com/title/tt0117500/"
|
"url" => "http://www.imdb.com/title/tt0117500/"
|
||||||
|
|
Loading…
Reference in New Issue