Migrate from embedded covers to assets

This commit is contained in:
Claudio Ortolina
2025-09-01 16:10:50 +03:00
parent cbf567a502
commit dc77d337c0
19 changed files with 80 additions and 144 deletions
@@ -31,10 +31,8 @@ defmodule MusicLibraryWeb.CollectionControllerTest do
"id" => record.id,
"artists" => ["Steven Wilson"],
"title" => record.title,
"cover_url" =>
"http://localhost:4002/api/covers/#{record.id}?vsn=#{record.cover_hash}",
"thumb_url" =>
"http://localhost:4002/api/covers/#{record.id}?vsn=#{record.cover_hash}&size=480"
"cover_url" => "http://localhost:4002/api/covers/#{record.cover_hash}",
"thumb_url" => "http://localhost:4002/api/covers/#{record.cover_hash}?size=480"
}
end
end
@@ -59,10 +57,8 @@ defmodule MusicLibraryWeb.CollectionControllerTest do
"id" => record.id,
"artists" => ["Steven Wilson"],
"title" => record.title,
"cover_url" =>
"http://localhost:4002/api/covers/#{record.id}?vsn=#{record.cover_hash}",
"thumb_url" =>
"http://localhost:4002/api/covers/#{record.id}?vsn=#{record.cover_hash}&size=480"
"cover_url" => "http://localhost:4002/api/covers/#{record.cover_hash}",
"thumb_url" => "http://localhost:4002/api/covers/#{record.cover_hash}?size=480"
}
end
end
@@ -91,10 +87,8 @@ defmodule MusicLibraryWeb.CollectionControllerTest do
"id" => record.id,
"artists" => ["Steven Wilson"],
"title" => record.title,
"cover_url" =>
"http://localhost:4002/api/covers/#{record.id}?vsn=#{record.cover_hash}",
"thumb_url" =>
"http://localhost:4002/api/covers/#{record.id}?vsn=#{record.cover_hash}&size=480"
"cover_url" => "http://localhost:4002/api/covers/#{record.cover_hash}",
"thumb_url" => "http://localhost:4002/api/covers/#{record.cover_hash}?size=480"
}
]
}
@@ -4,7 +4,6 @@ defmodule MusicLibraryWeb.CoverControllerTest do
import MusicLibrary.Fixtures.Records
alias MusicLibrary.Assets
alias MusicLibrary.Records.Cover
defp create_asset(_config) do
{:ok, asset} = Assets.store(%{content: marbles_cover_data(), format: "image/jpeg"})
@@ -65,7 +64,7 @@ defmodule MusicLibraryWeb.CoverControllerTest do
conn = get(conn, ~p"/covers/#{asset.hash}?size=480")
thumb = marbles_thumb_data()
hash = Cover.hash(thumb)
hash = Assets.Asset.hash(thumb)
assert conn.status == 200
assert get_resp_header(conn, "content-type") == ["image/jpeg; charset=utf-8"]
@@ -7,6 +7,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
import MusicLibraryWeb.RecordComponents, only: [format_label: 1, type_label: 1]
alias MusicBrainz.ReleaseGroupSearchResult
alias MusicLibrary.Assets
alias MusicLibrary.Records.{Cover, Record}
# make it a multiple of 4 for easier calculations
@@ -50,7 +51,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
session = visit(conn, ~p"/collection?order=alphabetical&page_size=#{page_size}")
for record <- expected_present do
cover_url = ~p"/covers/#{record.id}?vsn=#{record.cover_hash}"
cover_url = ~p"/covers/#{record.cover_hash}"
session
|> assert_has("#records-#{record.id}")
@@ -139,7 +140,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
session =
visit(conn, ~p"/collection?#{qs}")
cover_url = ~p"/covers/#{record.id}?vsn=#{record.cover_hash}"
cover_url = ~p"/covers/#{record.cover_hash}"
session
|> assert_has("#records-#{record.id}")
@@ -181,7 +182,7 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
visit(conn, ~p"/collection?#{qs}")
for record <- present do
cover_url = ~p"/covers/#{record.id}?vsn=#{record.cover_hash}"
cover_url = ~p"/covers/#{record.cover_hash}"
session
|> assert_has("#records-#{record.id}")
@@ -217,8 +218,8 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
end
test "can change the record cover", %{conn: conn} do
record = record(cover_data: marbles_cover_data())
cover_url = ~p"/covers/#{record.id}?vsn=#{record.cover_hash}"
record = record()
cover_url = ~p"/covers/#{record.cover_hash}"
session =
conn
@@ -231,10 +232,10 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
|> click_button("Save")
|> assert_has("p", text: "Record updated successfully")
updated_cover = MusicLibrary.Records.get_cover(record.id)
updated_cover_url = ~p"/covers/#{record.id}?vsn=#{updated_cover.cover_hash}"
updated_record = MusicLibrary.Records.get_record!(record.id)
updated_cover_url = ~p"/covers/#{updated_record.cover_hash}"
assert updated_cover.cover_hash !== record.cover_hash
assert updated_record.cover_hash !== record.cover_hash
assert_has(session, "img[src='#{updated_cover_url}']")
end
end
@@ -317,7 +318,9 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
{:ok, resized_cover_data} = Cover.resize(cover_data)
assert record.cover_data == resized_cover_data
assets = Assets.get(record.cover_hash)
assert assets.content == resized_cover_data
assert record.inserted_at !== nil
assert record.updated_at !== nil
@@ -420,9 +423,10 @@ defmodule MusicLibraryWeb.CollectionLive.IndexTest do
assert record.cover_hash ==
"E7238C742E5B8711FC5BFF01A4A1F727D9E404A4D1420429A6B37ABFFC0B5960"
asset = Assets.get(record.cover_hash)
{:ok, resized_cover_data} = Cover.resize(cover_data)
assert record.cover_data == resized_cover_data
assert asset.content == resized_cover_data
assert record.inserted_at !== nil
assert record.updated_at !== nil
@@ -29,7 +29,7 @@ defmodule MusicLibraryWeb.CollectionLive.ShowTest do
describe "Show record" do
test "it includes all needed information", %{conn: conn} do
record = record()
cover_url = ~p"/covers/#{record.id}?vsn=#{record.cover_hash}"
cover_url = ~p"/covers/#{record.cover_hash}"
release_response = Fixtures.Release.release(:marbles)
@@ -21,7 +21,7 @@ defmodule MusicLibraryWeb.WishlistLive.ShowTest do
describe "Show record" do
test "it includes all needed information", %{conn: conn} do
record = record(purchased_at: nil)
cover_url = ~p"/covers/#{record.id}?vsn=#{record.cover_hash}"
cover_url = ~p"/covers/#{record.cover_hash}"
session =
conn