akkoma/lib/pleroma/web/mastodon_api/mastodon_api.ex

21 lines
772 B
Elixir
Raw Normal View History

# Pleroma: A lightweight social networking server
# Copyright _ 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
2018-03-30 13:01:53 +00:00
defmodule Pleroma.Web.MastodonAPI do
alias Pleroma.{Repo, Activity, Object, HTML}
alias Pleroma.Web.ActivityPub.ActivityPub
def get_status_card(status_id) do
with %Activity{} = activity <- Repo.get(Activity, status_id),
true <- ActivityPub.is_public?(activity),
%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: page_url, rich_media: rich_media}
else
_ -> %{}
end
end
end