Something went wrong. Try again.
a simple but full-featured web player for OpenSubsonic music servers (Navidrome, Gonic, Ampache, etc) devins.page/tinysub
svelte typescript javascript subsonic gonic navidrome
Something went wrong. Try again.
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344import { SvelteMap } from "svelte/reactivity";import { sourceStorageKey } from "./sources.svelte.js";
type ArtworkSong = { albumId?: string; sourceId?: string; coverArt?: string; _radioStreamUrl?: string;};
const albumArtIds = new SvelteMap<string, string>();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 || "" );};