mirror of
https://github.com/rommapp/romm.git
synced 2026-12-05 05:07:31 +01:00
fix(soundtrack): fall back to the default cover when a game has no artwork (#4779)
The backend's Rom.path_cover_large/path_cover_small return "" rather than null for a ROM without a cover, and a complete rescan resets url_cover to "". resolveSoundtrackGameArtwork chained them with ??, so the empty string won and the v2 mini player rendered <img src=""> instead of the default album cover. The same value also leaked into the soundtrack panel's header art. Treat empty strings as missing in resolveSoundtrackGameArtwork and in playerCoverUrl, with tests for both. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -85,6 +85,19 @@ describe("resolveSoundtrackGameArtwork", () => {
|
||||
).toBe("small.png");
|
||||
expect(resolveSoundtrackGameArtwork(makeRom())).toBeUndefined();
|
||||
});
|
||||
|
||||
it("treats the backend's empty cover paths as missing", () => {
|
||||
expect(
|
||||
resolveSoundtrackGameArtwork(
|
||||
makeRom({ path_cover_large: "", path_cover_small: "", url_cover: "" }),
|
||||
),
|
||||
).toBeUndefined();
|
||||
expect(
|
||||
resolveSoundtrackGameArtwork(
|
||||
makeRom({ path_cover_large: "", path_cover_small: "small.png" }),
|
||||
),
|
||||
).toBe("small.png");
|
||||
});
|
||||
});
|
||||
|
||||
describe("loadPlaylist with preserved shuffle", () => {
|
||||
|
||||
@@ -72,8 +72,9 @@ export function resolveSoundtrackGameArtwork(
|
||||
const logoPath = rom.ss_metadata?.logo_path;
|
||||
if (logoPath) return `${FRONTEND_RESOURCES_PATH}/${logoPath}`;
|
||||
|
||||
// The backend sends "" rather than null for a ROM without a cover.
|
||||
return (
|
||||
rom.path_cover_large ?? rom.path_cover_small ?? rom.url_cover ?? undefined
|
||||
rom.path_cover_large || rom.path_cover_small || rom.url_cover || undefined
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -138,4 +138,13 @@ describe("playerCoverUrl", () => {
|
||||
expect(playerCoverUrl({ gameArtworkUrl: "/game.jpg" })).toBe("/game.jpg");
|
||||
expect(playerCoverUrl({})).toBe("/assets/default/album_cover.jpg");
|
||||
});
|
||||
|
||||
it("skips empty URLs instead of rendering a broken image", () => {
|
||||
expect(
|
||||
playerCoverUrl({ coverUrl: "", folderCoverUrl: "", gameArtworkUrl: "" }),
|
||||
).toBe("/assets/default/album_cover.jpg");
|
||||
expect(playerCoverUrl({ coverUrl: "", gameArtworkUrl: "/game.jpg" })).toBe(
|
||||
"/game.jpg",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -137,9 +137,9 @@ export function nowPlayingCaption(tags: NowPlayingTags | undefined): string {
|
||||
/** The mini player's cover: the track's own art, then the ROM's. */
|
||||
export function playerCoverUrl(meta: PlayerMeta): string {
|
||||
return (
|
||||
meta.coverUrl ??
|
||||
meta.folderCoverUrl ??
|
||||
meta.gameArtworkUrl ??
|
||||
meta.coverUrl ||
|
||||
meta.folderCoverUrl ||
|
||||
meta.gameArtworkUrl ||
|
||||
"/assets/default/album_cover.jpg"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user