From b0f4e18ef72d0ae9cd64777f859a73e84018b60b Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Wed, 17 Sep 2025 11:24:14 +0300 Subject: [PATCH] Fix API collection record cover URLs --- .../controllers/collection_json.ex | 6 ++++-- lib/music_library_web/router.ex | 2 +- .../controllers/collection_controller_test.exs | 18 ++++++++++++------ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/music_library_web/controllers/collection_json.ex b/lib/music_library_web/controllers/collection_json.ex index 70ee138d..0f9d8784 100644 --- a/lib/music_library_web/controllers/collection_json.ex +++ b/lib/music_library_web/controllers/collection_json.ex @@ -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 diff --git a/lib/music_library_web/router.ex b/lib/music_library_web/router.ex index b3f3f048..d248dc7a 100644 --- a/lib/music_library_web/router.ex +++ b/lib/music_library_web/router.ex @@ -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 diff --git a/test/music_library_web/controllers/collection_controller_test.exs b/test/music_library_web/controllers/collection_controller_test.exs index 3540f304..190ca072 100644 --- a/test/music_library_web/controllers/collection_controller_test.exs +++ b/test/music_library_web/controllers/collection_controller_test.exs @@ -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" } ] }