commit: 1bce20cc79ad4cd9ca46027eb64cf6b94922f932
parent: e4d57ebbc3290ee277e9f89ec42a9dd68f16b048
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Tue, 28 Apr 2020 02:36:55 +0200
status_view.ex, attachment: re-transmogrify, with block
Diffstat:
1 file changed, 40 insertions(+), 25 deletions(-)
diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex
@@ -14,6 +14,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.UserRelationship
+ alias Pleroma.Web.ActivityPub.Transmogrifier
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.MastodonAPI.AccountView
@@ -413,31 +414,45 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
def render("card.json", _), do: nil
- def render("attachment.json", %{attachment: attachment}) do
- [attachment_url | _] = attachment["url"]
- media_type = attachment_url["mediaType"] || attachment_url["mimeType"] || "image"
- href = attachment_url["href"] |> MediaProxy.url()
-
- type =
- cond do
- String.contains?(media_type, "image") -> "image"
- String.contains?(media_type, "video") -> "video"
- String.contains?(media_type, "audio") -> "audio"
- true -> "unknown"
- end
-
- <<hash_id::signed-32, _rest::binary>> = :crypto.hash(:md5, href)
-
- %{
- id: to_string(attachment["id"] || hash_id),
- url: href,
- remote_url: href,
- preview_url: href,
- text_url: href,
- type: type,
- description: attachment["name"],
- pleroma: %{mime_type: media_type}
- }
+ def render("attachment.json", object) do
+ with {_, %{attachment: attachment}} <-
+ {:fix_attachments, Transmogrifier.fix_attachments(object)},
+ {_, %{"url" => [attachment_url | _]}} <- {:attach_assign, attachment} do
+ href = attachment_url["href"]
+ media_type = attachment_url["mediaType"]
+
+ type =
+ cond do
+ String.contains?(media_type, "image") -> "image"
+ String.contains?(media_type, "video") -> "video"
+ String.contains?(media_type, "audio") -> "audio"
+ true -> "unknown"
+ end
+
+ attachment_id =
+ if attachment["id"] do
+ attachment["id"]
+ else
+ <<hash_id::signed-32, _rest::binary>> = :crypto.hash(:md5, href || "")
+
+ hash_id
+ end
+
+ %{
+ id: to_string(attachment_id),
+ url: href,
+ remote_url: href,
+ preview_url: href,
+ text_url: href,
+ type: type,
+ description: attachment["name"],
+ pleroma: %{mime_type: media_type}
+ }
+ else
+ e ->
+ Logger.warn("StatusView.render(\"attachment.json\", object): #{inspect(e)}")
+ %{}
+ end
end
def render("context.json", %{activity: activity, activities: activities, user: user}) do