From e158345674f0a7f51dbea65918e0d17190522194 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Thu, 18 Sep 2025 20:15:31 +0300 Subject: [PATCH] Change /covers to /assets --- .../components/record_components.ex | 2 +- .../controllers/artist_controller.ex | 4 ++-- ...cover_controller.ex => asset_controller.ex} | 2 +- .../controllers/collection_json.ex | 4 ++-- lib/music_library_web/router.ex | 4 ++-- ...ller_test.exs => asset_controller_test.exs} | 18 +++++++++--------- .../controllers/collection_controller_test.exs | 12 ++++++------ .../live/collection_live/index_test.exs | 2 +- .../live/collection_live/show_test.exs | 2 +- .../live/wishlist_live/show_test.exs | 2 +- 10 files changed, 26 insertions(+), 26 deletions(-) rename lib/music_library_web/controllers/{cover_controller.ex => asset_controller.ex} (97%) rename test/music_library_web/controllers/{cover_controller_test.exs => asset_controller_test.exs} (85%) diff --git a/lib/music_library_web/components/record_components.ex b/lib/music_library_web/components/record_components.ex index ee84dd47..37f73573 100644 --- a/lib/music_library_web/components/record_components.ex +++ b/lib/music_library_web/components/record_components.ex @@ -21,7 +21,7 @@ defmodule MusicLibraryWeb.RecordComponents do {@record.title} """ end diff --git a/lib/music_library_web/controllers/artist_controller.ex b/lib/music_library_web/controllers/artist_controller.ex index 662cddd6..49f47f85 100644 --- a/lib/music_library_web/controllers/artist_controller.ex +++ b/lib/music_library_web/controllers/artist_controller.ex @@ -3,7 +3,7 @@ defmodule MusicLibraryWeb.ArtistController do alias MusicLibrary.Artists alias MusicLibrary.Assets.Transform - alias MusicLibraryWeb.CoverController + alias MusicLibraryWeb.AssetController def image(conn, %{"musicbrainz_id" => artist_id}) do case Artists.get_image(artist_id) do @@ -15,7 +15,7 @@ defmodule MusicLibraryWeb.ArtistController do %Transform{hash: hash} |> Transform.encode!() - CoverController.show(conn, %{"transform_payload" => payload}) + AssetController.show(conn, %{"transform_payload" => payload}) end end diff --git a/lib/music_library_web/controllers/cover_controller.ex b/lib/music_library_web/controllers/asset_controller.ex similarity index 97% rename from lib/music_library_web/controllers/cover_controller.ex rename to lib/music_library_web/controllers/asset_controller.ex index b8c918f0..5e514116 100644 --- a/lib/music_library_web/controllers/cover_controller.ex +++ b/lib/music_library_web/controllers/asset_controller.ex @@ -1,4 +1,4 @@ -defmodule MusicLibraryWeb.CoverController do +defmodule MusicLibraryWeb.AssetController do use MusicLibraryWeb, :controller alias MusicLibrary.Assets diff --git a/lib/music_library_web/controllers/collection_json.ex b/lib/music_library_web/controllers/collection_json.ex index 0f9d8784..3afe1e85 100644 --- a/lib/music_library_web/controllers/collection_json.ex +++ b/lib/music_library_web/controllers/collection_json.ex @@ -21,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/#{%Transform{hash: record.cover_hash}}"), - thumb_url: url(~p"/api/covers/#{%Transform{hash: record.cover_hash, width: 480}}") + cover_url: url(~p"/api/assets/#{%Transform{hash: record.cover_hash}}"), + thumb_url: url(~p"/api/assets/#{%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 d248dc7a..f8c3d4b2 100644 --- a/lib/music_library_web/router.ex +++ b/lib/music_library_web/router.ex @@ -36,7 +36,7 @@ defmodule MusicLibraryWeb.Router do get "/backup", ArchiveController, :backup - get "/covers/:transform_payload", CoverController, :show + get "/assets/:transform_payload", AssetController, :show get "/artists/:musicbrainz_id/image", ArtistController, :image live_session :default, @@ -82,7 +82,7 @@ defmodule MusicLibraryWeb.Router do get "/collection/latest", CollectionController, :latest get "/collection/random", CollectionController, :random get "/collection", CollectionController, :index - get "/covers/:transform_payload", CoverController, :show + get "/assets/:transform_payload", AssetController, :show get "/backup", ArchiveController, :backup end diff --git a/test/music_library_web/controllers/cover_controller_test.exs b/test/music_library_web/controllers/asset_controller_test.exs similarity index 85% rename from test/music_library_web/controllers/cover_controller_test.exs rename to test/music_library_web/controllers/asset_controller_test.exs index 53529fe6..4cfebc36 100644 --- a/test/music_library_web/controllers/cover_controller_test.exs +++ b/test/music_library_web/controllers/asset_controller_test.exs @@ -1,4 +1,4 @@ -defmodule MusicLibraryWeb.CoverControllerTest do +defmodule MusicLibraryWeb.AssetControllerTest do use MusicLibraryWeb.ConnCase import MusicLibrary.Fixtures.Records @@ -12,21 +12,21 @@ defmodule MusicLibraryWeb.CoverControllerTest do %{asset: asset} end - describe "GET /covers/:payload" do + describe "GET /assets/:payload" do setup [:create_asset] test "404s when asset doesn't exist", %{conn: conn} do transform = %Transform{hash: Ecto.UUID.generate()} payload = Transform.encode!(transform) - conn = get(conn, ~p"/covers/#{payload}") + conn = get(conn, ~p"/assets/#{payload}") assert text_response(conn, 404) == "Not found" end - test "serves the cover without etag", %{conn: conn, asset: asset} do + test "serves the asset without etag", %{conn: conn, asset: asset} do transform = %Transform{hash: asset.hash} payload = Transform.encode!(transform) - conn = get(conn, ~p"/covers/#{payload}") + conn = get(conn, ~p"/assets/#{payload}") assert conn.status == 200 assert get_resp_header(conn, "content-type") == ["image/jpeg; charset=utf-8"] @@ -36,14 +36,14 @@ defmodule MusicLibraryWeb.CoverControllerTest do assert conn.resp_body == asset.content end - test "serves the cover when etag doesn't match", %{conn: conn, asset: asset} do + test "serves the asset when etag doesn't match", %{conn: conn, asset: asset} do transform = %Transform{hash: asset.hash} payload = Transform.encode!(transform) conn = conn |> put_req_header("if-none-match", "invalid-etag") - |> get(~p"/covers/#{payload}") + |> get(~p"/assets/#{payload}") assert conn.status == 200 assert get_resp_header(conn, "content-type") == ["image/jpeg; charset=utf-8"] @@ -60,7 +60,7 @@ defmodule MusicLibraryWeb.CoverControllerTest do conn = conn |> put_req_header("if-none-match", payload) - |> get(~p"/covers/#{payload}") + |> get(~p"/assets/#{payload}") assert conn.status == 304 assert get_resp_header(conn, "content-type") == [] @@ -74,7 +74,7 @@ defmodule MusicLibraryWeb.CoverControllerTest do transform = %Transform{hash: asset.hash, width: 480} payload = Transform.encode!(transform) - conn = get(conn, ~p"/covers/#{payload}") + conn = get(conn, ~p"/assets/#{payload}") assert conn.status == 200 assert get_resp_header(conn, "content-type") == ["image/jpeg; charset=utf-8"] diff --git a/test/music_library_web/controllers/collection_controller_test.exs b/test/music_library_web/controllers/collection_controller_test.exs index 190ca072..924a136b 100644 --- a/test/music_library_web/controllers/collection_controller_test.exs +++ b/test/music_library_web/controllers/collection_controller_test.exs @@ -32,9 +32,9 @@ defmodule MusicLibraryWeb.CollectionControllerTest do "artists" => ["Steven Wilson"], "title" => record.title, "cover_url" => - "http://localhost:4002/api/covers/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjpudWxsfQ", + "http://localhost:4002/api/assets/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjpudWxsfQ", "thumb_url" => - "http://localhost:4002/api/covers/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjo0ODB9" + "http://localhost:4002/api/assets/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjo0ODB9" } end end @@ -60,9 +60,9 @@ defmodule MusicLibraryWeb.CollectionControllerTest do "artists" => ["Steven Wilson"], "title" => record.title, "cover_url" => - "http://localhost:4002/api/covers/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjpudWxsfQ", + "http://localhost:4002/api/assets/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjpudWxsfQ", "thumb_url" => - "http://localhost:4002/api/covers/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjo0ODB9" + "http://localhost:4002/api/assets/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjo0ODB9" } end end @@ -92,9 +92,9 @@ defmodule MusicLibraryWeb.CollectionControllerTest do "artists" => ["Steven Wilson"], "title" => record.title, "cover_url" => - "http://localhost:4002/api/covers/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjpudWxsfQ", + "http://localhost:4002/api/assets/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjpudWxsfQ", "thumb_url" => - "http://localhost:4002/api/covers/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjo0ODB9" + "http://localhost:4002/api/assets/eyJoYXNoIjoiNTk5NDA3RERGNjk5MDdENEE2MEZFMTNDQ0FBODI0RDI1Q0YwOERDMTI0RkQ2QUEzRThFN0VDRDk4Qzg4NUZGRSIsIndpZHRoIjo0ODB9" } ] } diff --git a/test/music_library_web/live/collection_live/index_test.exs b/test/music_library_web/live/collection_live/index_test.exs index 9c885d20..78fe8af0 100644 --- a/test/music_library_web/live/collection_live/index_test.exs +++ b/test/music_library_web/live/collection_live/index_test.exs @@ -446,6 +446,6 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do defp cover_url(record, width) do transform = %Transform{hash: record.cover_hash, width: width} payload = Transform.encode!(transform) - ~p"/covers/#{payload}" + ~p"/assets/#{payload}" end end diff --git a/test/music_library_web/live/collection_live/show_test.exs b/test/music_library_web/live/collection_live/show_test.exs index 6a342507..8c2a6eec 100644 --- a/test/music_library_web/live/collection_live/show_test.exs +++ b/test/music_library_web/live/collection_live/show_test.exs @@ -32,7 +32,7 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do record = record() transform = %Transform{hash: record.cover_hash, width: nil} payload = Transform.encode!(transform) - cover_url = ~p"/covers/#{payload}" + cover_url = ~p"/assets/#{payload}" release_response = Fixtures.Release.release(:marbles) diff --git a/test/music_library_web/live/wishlist_live/show_test.exs b/test/music_library_web/live/wishlist_live/show_test.exs index 8af1ec47..bd2fbd75 100644 --- a/test/music_library_web/live/wishlist_live/show_test.exs +++ b/test/music_library_web/live/wishlist_live/show_test.exs @@ -24,7 +24,7 @@ defmodule MusicLibraryWeb.WishlistLive.ShowTest do record = record(purchased_at: nil) transform = %Transform{hash: record.cover_hash, width: nil} payload = Transform.encode!(transform) - cover_url = ~p"/covers/#{payload}" + cover_url = ~p"/assets/#{payload}" session = conn