diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index d1022f5a1..bdd65beda 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -242,9 +242,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do true -> CommonAPI.thread_muted?(opts[:for], activity) end - attachment_data = object.data["attachments"] || [] + attachment_data = object.data["attachment"] || [] # attachments = render_many(attachment_data, StatusView, "attachment.json", as: :attachment) - attachments = render_many(attachment_data, StatusView, "media.json", as: :media) + attachments = render_many(attachment_data, StatusView, "object_media.json", as: :media) created_at = Utils.to_masto_date(object.data["published"]) @@ -437,6 +437,33 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do } end + def render("object_media.json", %{media: media}) do + [url] = media["url"] + media_type = media["mediaType"] || "image" + href = MediaProxy.url(url["href"]) + href_preview = MediaProxy.preview_url(url["href"]) + + type = + cond do + String.contains?(media_type, "image") -> "image" + String.contains?(media_type, "video") -> "video" + String.contains?(media_type, "audio") -> "audio" + true -> "unknown" + end + + %{ + id: to_string(media["id"]), + url: href, + remote_url: href, + preview_url: href_preview, + text_url: href, + type: type, + description: media["name"], + pleroma: %{mime_type: media_type}, + blurhash: media["blurhash"] + } + end + def render("media.json", %{media: media}) do media_type = media.media_type || media.mime_type || "image" href = MediaProxy.url(media.href)