1
0
Fork 0
mirror of https://framagit.org/framasoft/mobilizon.git synced 2025-01-22 08:38:38 +00:00

fix(activitypub): remote event processing fails when featured image is of type Image

This commit is contained in:
André Menrath 2025-01-12 22:55:36 +01:00 committed by setop
parent 56b17f17bf
commit ed85ae2bee

View file

@ -30,18 +30,19 @@ defmodule Mobilizon.Federation.ActivityStream.Converter.Media do
""" """
@spec find_or_create_media(map(), String.t() | integer()) :: @spec find_or_create_media(map(), String.t() | integer()) ::
{:ok, MediaModel.t()} | {:error, atom() | String.t() | Ecto.Changeset.t()} {:ok, MediaModel.t()} | {:error, atom() | String.t() | Ecto.Changeset.t()}
def find_or_create_media(%{"type" => "Link", "href" => url}, actor_id), def find_or_create_media(%{"type" => type, "href" => url}, actor_id)
when type in ["Image", "Document"],
do: do:
find_or_create_media( find_or_create_media(
%{"type" => "Document", "url" => url, "name" => "External media"}, %{"type" => type, "url" => url, "name" => "External media"},
actor_id actor_id
) )
def find_or_create_media( def find_or_create_media(
%{"type" => "Document", "url" => media_url, "name" => name}, %{"type" => type, "url" => media_url, "name" => name},
actor_id 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 with {:ok, %{url: url} = uploaded} <- upload_media(media_url, name) do
case Medias.get_media_by_url(url) do case Medias.get_media_by_url(url) do
%MediaModel{file: _file} = media -> %MediaModel{file: _file} = media ->