From 63d44ce4dba43e788dd8c59cb02039c57f7628c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Fri, 29 Aug 2025 11:42:14 +0200 Subject: [PATCH] fix(activitypub): Remote event processing fails if featured image is of type `Image` --- .../activity_stream/converter/media.ex | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/federation/activity_stream/converter/media.ex b/lib/federation/activity_stream/converter/media.ex index c98f429ee..a9be37a7e 100644 --- a/lib/federation/activity_stream/converter/media.ex +++ b/lib/federation/activity_stream/converter/media.ex @@ -2,7 +2,7 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Media do @moduledoc """ Media converter. - This module allows to convert events from ActivityStream format to our own + This module allows converting events from ActivityStream format to our own internal one, and back. """ @@ -12,6 +12,8 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Media do alias Mobilizon.Service.HTTP.RemoteMediaDownloaderClient alias Mobilizon.Web.Upload + @supported_media_types ["Image", "Document"] + @doc """ Convert a media struct to an ActivityStream representation. """ @@ -30,19 +32,18 @@ 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" => 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" => type, "href" => url}, actor_id) when type in @supported_media_types, + do: + find_or_create_media( + %{"type" => type, "url" => url, "name" => "External media"}, + actor_id + ) def find_or_create_media( %{"type" => type, "url" => media_url, "name" => name}, actor_id ) - when type in ["Image", "Document"] and is_binary(media_url) do + when type in @supported_media_types 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 ->