aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>2019-01-14 00:06:55 +0100
committerWilliam Pitcock <nenolod@dereferenced.org>2019-01-26 14:18:23 +0000
commit3f64379b1382f2e26cacd28da230c67bf68656a0 (patch)
treef8e970e40675e6d79fefc07ef7acb8bf2259da22 /lib
parentd9f3af477d687fb8cb469ec652586911ad51d0b0 (diff)
downloadpleroma-3f64379b1382f2e26cacd28da230c67bf68656a0.tar.gz
Web.MastodonAPI.MastodonAPIController: Add Rich-Media support
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/mastodon_api/mastodon_api_controller.ex23
-rw-r--r--lib/pleroma/web/router.ex2
2 files changed, 24 insertions, 1 deletions
diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
index f4736fcb5..86607e7af 100644
--- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
+++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
@@ -1322,6 +1322,29 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
end
end
+ defp status_first_external_url(content) do
+ content
+ |> Floki.filter_out("a.mention")
+ |> Floki.attribute("a", "href")
+ |> Enum.at(0)
+ end
+
+ def status_card(conn, %{"id" => status_id}) do
+ with %Activity{} = activity <- Repo.get(Activity, status_id),
+ true <- ActivityPub.is_public?(activity),
+ page_url <- status_first_external_url(activity.data["object"]["content"]),
+ {:ok, rich_media} <- Pleroma.Web.RichMedia.Parser.parse(page_url) do
+ card =
+ rich_media
+ |> Map.take([:image, :title, :url, :description])
+ |> Map.put(:type, "link")
+
+ json(conn, card)
+ else
+ _ -> json(conn, %{})
+ end
+ end
+
def try_render(conn, target, params)
when is_binary(target) do
res = render(conn, target, params)
diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex
index b83790858..e749aa834 100644
--- a/lib/pleroma/web/router.ex
+++ b/lib/pleroma/web/router.ex
@@ -258,7 +258,7 @@ defmodule Pleroma.Web.Router do
get("/statuses/:id", MastodonAPIController, :get_status)
get("/statuses/:id/context", MastodonAPIController, :get_context)
- get("/statuses/:id/card", MastodonAPIController, :empty_object)
+ get("/statuses/:id/card", MastodonAPIController, :status_card)
get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by)
get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by)