mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2026-02-15 17:16:57 +00:00
Add Actor images normalization from array of urls to string
This commit is contained in:
parent
c8fc821a0e
commit
4985902b02
4 changed files with 84 additions and 1 deletions
1
changelog.d/normalize-actor-image-hrefs.fix
Normal file
1
changelog.d/normalize-actor-image-hrefs.fix
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Add Actor images normalization from array of urls to string
|
||||||
|
|
@ -1569,7 +1569,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
|
|
||||||
defp get_actor_url(_url), do: nil
|
defp get_actor_url(_url), do: nil
|
||||||
|
|
||||||
defp normalize_image(%{"url" => url} = data) do
|
defp normalize_image(%{"url" => url} = data) when is_binary(url) do
|
||||||
%{
|
%{
|
||||||
"type" => "Image",
|
"type" => "Image",
|
||||||
"url" => [%{"href" => url}]
|
"url" => [%{"href" => url}]
|
||||||
|
|
@ -1577,6 +1577,13 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
||||||
|> maybe_put_description(data)
|
|> maybe_put_description(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp normalize_image(%{"url" => urls}) when is_list(urls) do
|
||||||
|
url = urls |> List.first()
|
||||||
|
|
||||||
|
%{"url" => url}
|
||||||
|
|> normalize_image()
|
||||||
|
end
|
||||||
|
|
||||||
defp normalize_image(urls) when is_list(urls), do: urls |> List.first() |> normalize_image()
|
defp normalize_image(urls) when is_list(urls), do: urls |> List.first() |> normalize_image()
|
||||||
defp normalize_image(_), do: nil
|
defp normalize_image(_), do: nil
|
||||||
|
|
||||||
|
|
|
||||||
41
test/fixtures/users_mock/href_as_array.json
vendored
Normal file
41
test/fixtures/users_mock/href_as_array.json
vendored
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
{
|
||||||
|
"alsoKnownAs": [],
|
||||||
|
"attachment": [],
|
||||||
|
"capabilities": {},
|
||||||
|
"discoverable": true,
|
||||||
|
"endpoints": {},
|
||||||
|
"featured": "https://queef.in/cute_cat/collections/featured",
|
||||||
|
"followers": "https://queef.in/cute_cat/followers",
|
||||||
|
"following": "https://queef.in/cute_cat/following",
|
||||||
|
"icon": {
|
||||||
|
"type": "Image",
|
||||||
|
"url": [
|
||||||
|
"https://queef.in/storage/profile.webp",
|
||||||
|
"https://example.com/image"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"id": "https://queef.in/cute_cat",
|
||||||
|
"image": {
|
||||||
|
"type": "Image",
|
||||||
|
"url": [
|
||||||
|
"https://queef.in/storage/banner.gif",
|
||||||
|
"https://example.com/image"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"inbox": "https://queef.in/cute_cat/inbox",
|
||||||
|
"manuallyApprovesFollowers": false,
|
||||||
|
"name": "cute_cat",
|
||||||
|
"outbox": "https://queef.in/cute_cat/outbox",
|
||||||
|
"preferredUsername": "cute_cat",
|
||||||
|
"publicKey": {
|
||||||
|
"id": "https://queef.in/cute_cat#main-key",
|
||||||
|
"owner": "https://queef.in/cute_cat"
|
||||||
|
},
|
||||||
|
"published": "2025-08-18T01:16:10.000Z",
|
||||||
|
"summary": "A cute cat",
|
||||||
|
"tag": [],
|
||||||
|
"type": "Person",
|
||||||
|
"url": "https://queef.in/cute_cat",
|
||||||
|
"vcard:bday": null,
|
||||||
|
"webfinger": "acct:cute_cat@queef.in"
|
||||||
|
}
|
||||||
|
|
@ -465,6 +465,40 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "works with avatar/banner href as list" do
|
||||||
|
user_id = "https://queef.in/cute_cat"
|
||||||
|
|
||||||
|
user_data =
|
||||||
|
"test/fixtures/users_mock/href_as_array.json"
|
||||||
|
|> File.read!()
|
||||||
|
|> Jason.decode!()
|
||||||
|
|> Map.delete("featured")
|
||||||
|
|> Jason.encode!()
|
||||||
|
|
||||||
|
Tesla.Mock.mock(fn
|
||||||
|
%{
|
||||||
|
method: :get,
|
||||||
|
url: ^user_id
|
||||||
|
} ->
|
||||||
|
%Tesla.Env{
|
||||||
|
status: 200,
|
||||||
|
body: user_data,
|
||||||
|
headers: [{"content-type", "application/activity+json"}]
|
||||||
|
}
|
||||||
|
end)
|
||||||
|
|
||||||
|
{:ok, user} = ActivityPub.make_user_from_ap_id(user_id)
|
||||||
|
|
||||||
|
assert length(user.avatar["url"]) == 1
|
||||||
|
assert length(user.banner["url"]) == 1
|
||||||
|
|
||||||
|
assert user.avatar["url"] |> List.first() |> Map.fetch!("href") ==
|
||||||
|
"https://queef.in/storage/profile.webp"
|
||||||
|
|
||||||
|
assert user.banner["url"] |> List.first() |> Map.fetch!("href") ==
|
||||||
|
"https://queef.in/storage/banner.gif"
|
||||||
|
end
|
||||||
|
|
||||||
test "it fetches the appropriate tag-restricted posts" do
|
test "it fetches the appropriate tag-restricted posts" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue