From ef2edefc4ca45194a3e3c814e62ae98c665081e8 Mon Sep 17 00:00:00 2001 From: trentisiete Date: Fri, 3 Apr 2026 14:27:55 +0200 Subject: [PATCH] fix: normalize artist ID comparison to handle string/number types --- js/api.js | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/js/api.js b/js/api.js index 0c7c919..199fc1f 100644 --- a/js/api.js +++ b/js/api.js @@ -1073,18 +1073,20 @@ export class LosslessAPI { entries.forEach((entry) => scan(entry, visited)); scan(primaryData, visited); - const numericArtistId = Number(artistId); + const matchesArtistId = (item) => { + const candidateIds = [ + item.artist?.id, + ...(Array.isArray(item.artists) ? item.artists.map((a) => a.id) : []), + ].filter((id) => id != null); + return candidateIds.some((id) => Number(id) === Number(artistId)); + }; + if (!options.lightweight) { try { const videoSearch = await this.searchVideos(artist.name); if (videoSearch && videoSearch.items) { for (const item of videoSearch.items) { - const itemArtistId = item.artist?.id; - const matchesArtist = - itemArtistId === numericArtistId || - (Array.isArray(item.artists) && item.artists.some((a) => a.id === numericArtistId)); - - if (matchesArtist && !videoMap.has(item.id)) { + if (matchesArtistId(item) && !videoMap.has(item.id)) { videoMap.set(item.id, item); } } @@ -1094,11 +1096,7 @@ export class LosslessAPI { } } - const rawReleases = Array.from(albumMap.values()).filter((album) => { - const albumArtistId = album.artist?.id; - return albumArtistId === numericArtistId || - (Array.isArray(album.artists) && album.artists.some((a) => a.id === numericArtistId)); - }); + const rawReleases = Array.from(albumMap.values()).filter(matchesArtistId); const allReleases = this.deduplicateAlbums(rawReleases).sort( (a, b) => new Date(b.releaseDate || 0) - new Date(a.releaseDate || 0) ); @@ -1107,11 +1105,7 @@ export class LosslessAPI { const albums = allReleases.filter((a) => !eps.includes(a)); const topTracks = Array.from(trackMap.values()) - .filter((track) => { - const trackArtistId = track.artist?.id; - return trackArtistId === numericArtistId || - (Array.isArray(track.artists) && track.artists.some((a) => a.id === numericArtistId)); - }) + .filter(matchesArtistId) .sort((a, b) => (b.popularity || 0) - (a.popularity || 0)) .slice(0, 15);