From 1f7843b9b8afcb559c8ba59388724dbf4ef3e3c9 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 26 Jan 2019 15:20:27 +0000 Subject: [PATCH] mastodon api: use OGP uri instead of page_url for deducing domain name, fix test --- lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 4 +++- test/web/mastodon_api/mastodon_api_controller_test.exs | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index ae744da60..a60532b55 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -1329,12 +1329,14 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do %Object{} = object <- Object.normalize(activity.data["object"]), page_url <- HTML.extract_first_external_url(object, object.data["content"]), {: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 rich_media - |> Map.take([:image, :title, :url, :description]) + |> Map.take([:image, :title, :description]) |> Map.put(:type, "link") |> Map.put(:provider_name, site_name) + |> Map.put(:url, page_url) else _ -> %{} end diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs index bc87383f7..55e778e4f 100644 --- a/test/web/mastodon_api/mastodon_api_controller_test.exs +++ b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -1634,6 +1634,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do assert response == %{ "image" => "http://ia.media-imdb.com/images/rock.jpg", + "provider_name" => "www.imdb.com", "title" => "The Rock", "type" => "link", "url" => "http://www.imdb.com/title/tt0117500/" -- 2.44.2