-# Pleroma: A lightweight social networking server
-# Copyright _ 2017-2019 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-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
alias Pleroma.{Repo, Object, Activity, User, Notification, Stats}
alias Pleroma.Web
- alias Pleroma.Web.MastodonAPI
-
alias Pleroma.Web.MastodonAPI.{
StatusView,
AccountView,
end
def status_card(conn, %{"id" => status_id}) do
- data = StatusView.render("card.json", MastodonAPI.get_status_card(status_id))
+ with %Activity{} = activity <- Repo.get(Activity, status_id),
+ true <- ActivityPub.is_public?(activity) do
+ data =
+ StatusView.render(
+ "card.json",
+ Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
+ )
- json(conn, data)
+ json(conn, data)
+ else
+ _e ->
+ %{}
+ end
end
def try_render(conn, target, params)
alias Pleroma.User
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.MediaProxy
- alias Pleroma.Web.MastodonAPI
alias Pleroma.Web.MastodonAPI.AccountView
alias Pleroma.Web.MastodonAPI.StatusView
__MODULE__
)
- card = render("card.json", MastodonAPI.get_status_card(activity.id))
+ card = render("card.json", Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity))
%{
id: to_string(activity.id),
--- /dev/null
+# Pleroma: A lightweight social networking server
+# Copyright _ 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.RichMedia.Helpers do
+ alias Pleroma.{Repo, Activity, Object, HTML}
+ alias Pleroma.Web.RichMedia.Parser
+
+ def fetch_data_for_activity(%Activity{} = activity) do
+ with %Object{} = object <- Object.normalize(activity.data["object"]),
+ page_url <- HTML.extract_first_external_url(object, object.data["content"]),
+ {:ok, rich_media} <- Parser.parse(page_url) do
+ %{page_url: page_url, rich_media: rich_media}
+ else
+ _ -> %{}
+ end
+ end
+end
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Formatter
alias Pleroma.HTML
- alias Pleroma.Web.MastodonAPI
alias Pleroma.Web.MastodonAPI.StatusView
defp user_by_ap_id(user_list, ap_id) do
summary = HTML.strip_tags(object["summary"])
- card = StatusView.render("card.json", MastodonAPI.get_status_card(activity.id))
+ card =
+ StatusView.render(
+ "card.json",
+ Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
+ )
%{
"id" => activity.id,
alias Pleroma.Web.TwitterAPI.ActivityView
alias Pleroma.Web.TwitterAPI.TwitterAPI
alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter
- alias Pleroma.Web.MastodonAPI
alias Pleroma.Web.MastodonAPI.StatusView
alias Pleroma.Activity
alias Pleroma.HTML
summary = HTML.strip_tags(summary)
- card = StatusView.render("card.json", MastodonAPI.get_status_card(activity.id))
+ card =
+ StatusView.render(
+ "card.json",
+ Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
+ )
%{
"id" => activity.id,