commit: 3e4118a56709dd7da99e63d1f4e10785e38abd42
parent: 3438fcb07c2b6f37f17722dc82e963a1865b064e
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
@@ -409,31 +410,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("listen.json", %{activity: %Activity{data: %{"type" => "Listen"}} = activity} = opts) do