commit: 5c9d58fd6d2cb71f01abf933986e95dc4892f432
parent: 3e4118a56709dd7da99e63d1f4e10785e38abd42
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Tue, 28 Apr 2020 06:27:45 +0200
Revert "status_view.ex, attachment: re-transmogrify, with block"
This reverts commit 79d907fe15590b6c8b2963856307da05cb2bbadb.
Diffstat:
1 file changed, 25 insertions(+), 40 deletions(-)
diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex
@@ -14,7 +14,6 @@ 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
@@ -410,45 +409,31 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
def render("card.json", _), do: nil
- 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
+ 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}
+ }
end
def render("listen.json", %{activity: %Activity{data: %{"type" => "Listen"}} = activity} = opts) do