Fix API collection record cover URLs

This commit is contained in:
Claudio Ortolina
2025-09-17 11:24:14 +03:00
parent 0996b78c7b
commit b0f4e18ef7
3 changed files with 17 additions and 9 deletions
@@ -1,6 +1,8 @@
defmodule MusicLibraryWeb.CollectionJSON do
use MusicLibraryWeb, :json
alias MusicLibrary.Assets.Transform
def show(%{record: record}) do
record(record)
end
@@ -19,8 +21,8 @@ defmodule MusicLibraryWeb.CollectionJSON do
id: record.id,
artists: Enum.map(record.artists, & &1.name),
title: record.title,
cover_url: url(~p"/api/covers/#{record.cover_hash}"),
thumb_url: url(~p"/api/covers/#{record.cover_hash}?#{[size: 480]}")
cover_url: url(~p"/api/covers/#{%Transform{hash: record.cover_hash}}"),
thumb_url: url(~p"/api/covers/#{%Transform{hash: record.cover_hash, width: 480}}")
}
end
end
+1 -1
View File
@@ -82,7 +82,7 @@ defmodule MusicLibraryWeb.Router do
get "/collection/latest", CollectionController, :latest
get "/collection/random", CollectionController, :random
get "/collection", CollectionController, :index
get "/covers/:hash", CoverController, :show
get "/covers/:transform_payload", CoverController, :show
get "/backup", ArchiveController, :backup
end
@@ -31,8 +31,10 @@ defmodule MusicLibraryWeb.CollectionControllerTest do
"id" => record.id,
"artists" => ["Steven Wilson"],
"title" => record.title,
"cover_url" => "http://localhost:4002/api/covers/#{record.cover_hash}",
"thumb_url" => "http://localhost:4002/api/covers/#{record.cover_hash}?size=480"
"cover_url" =>
"http://localhost:4002/api/covers/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjpudWxsfQ",
"thumb_url" =>
"http://localhost:4002/api/covers/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjo0ODB9"
}
end
end
@@ -57,8 +59,10 @@ defmodule MusicLibraryWeb.CollectionControllerTest do
"id" => record.id,
"artists" => ["Steven Wilson"],
"title" => record.title,
"cover_url" => "http://localhost:4002/api/covers/#{record.cover_hash}",
"thumb_url" => "http://localhost:4002/api/covers/#{record.cover_hash}?size=480"
"cover_url" =>
"http://localhost:4002/api/covers/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjpudWxsfQ",
"thumb_url" =>
"http://localhost:4002/api/covers/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjo0ODB9"
}
end
end
@@ -87,8 +91,10 @@ defmodule MusicLibraryWeb.CollectionControllerTest do
"id" => record.id,
"artists" => ["Steven Wilson"],
"title" => record.title,
"cover_url" => "http://localhost:4002/api/covers/#{record.cover_hash}",
"thumb_url" => "http://localhost:4002/api/covers/#{record.cover_hash}?size=480"
"cover_url" =>
"http://localhost:4002/api/covers/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjpudWxsfQ",
"thumb_url" =>
"http://localhost:4002/api/covers/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjo0ODB9"
}
]
}