From ed85ae2bee82068cdd7a1204df4d156c7d35c172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Sun, 12 Jan 2025 22:55:36 +0100 Subject: [PATCH] fix(activitypub): remote event processing fails when featured image is of type Image --- .../activity_stream/converter/media.ex | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/federation/activity_stream/converter/media.ex b/lib/federation/activity_stream/converter/media.ex index 5af0d0485..c98f429ee 100644 --- a/lib/federation/activity_stream/converter/media.ex +++ b/lib/federation/activity_stream/converter/media.ex @@ -30,18 +30,19 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Media do """ @spec find_or_create_media(map(), String.t() | integer()) :: {:ok, MediaModel.t()} | {:error, atom() | String.t() | Ecto.Changeset.t()} - def find_or_create_media(%{"type" => "Link", "href" => url}, actor_id), - do: - find_or_create_media( - %{"type" => "Document", "url" => url, "name" => "External media"}, - actor_id - ) + def find_or_create_media(%{"type" => type, "href" => url}, actor_id) + when type in ["Image", "Document"], + do: + find_or_create_media( + %{"type" => type, "url" => url, "name" => "External media"}, + actor_id + ) def find_or_create_media( - %{"type" => "Document", "url" => media_url, "name" => name}, + %{"type" => type, "url" => media_url, "name" => name}, actor_id ) - when is_binary(media_url) do + when type in ["Image", "Document"] and is_binary(media_url) do with {:ok, %{url: url} = uploaded} <- upload_media(media_url, name) do case Medias.get_media_by_url(url) do %MediaModel{file: _file} = media ->