import { SvelteMap } from "svelte/reactivity"; import { sourceStorageKey } from "./sources.svelte.js"; type ArtworkSong = { albumId?: string; sourceId?: string; coverArt?: string; _radioStreamUrl?: string; }; const albumArtIds = new SvelteMap(); const albumArtKey = (id: string, sourceId?: string) => sourceId ? sourceStorageKey(sourceId, id) : id; export const rememberAlbumArt = (album: { id?: string; sourceId?: string; coverArt?: string; }) => { if (album.id && album.coverArt) albumArtIds.set(albumArtKey(album.id, album.sourceId), album.coverArt); }; export const normalizeSongArt = (song: ArtworkSong) => { if (song._radioStreamUrl || !song.albumId) return; const key = albumArtKey(song.albumId, song.sourceId); const artId = albumArtIds.get(key); if (artId) { song.coverArt = artId; } else if (song.coverArt) { albumArtIds.set(key, song.coverArt); } }; export const songArtId = (song: ArtworkSong) => { if (song._radioStreamUrl) return song.coverArt || ""; return ( (song.albumId && albumArtIds.get(albumArtKey(song.albumId, song.sourceId))) || song.coverArt || "" ); };