fix: normalize artist ID comparison to handle string/number types
This commit is contained in:
parent
fbe101050a
commit
ef2edefc4c
1 changed files with 11 additions and 17 deletions
28
js/api.js
28
js/api.js
|
|
@ -1073,18 +1073,20 @@ export class LosslessAPI {
|
||||||
entries.forEach((entry) => scan(entry, visited));
|
entries.forEach((entry) => scan(entry, visited));
|
||||||
scan(primaryData, 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) {
|
if (!options.lightweight) {
|
||||||
try {
|
try {
|
||||||
const videoSearch = await this.searchVideos(artist.name);
|
const videoSearch = await this.searchVideos(artist.name);
|
||||||
if (videoSearch && videoSearch.items) {
|
if (videoSearch && videoSearch.items) {
|
||||||
for (const item of videoSearch.items) {
|
for (const item of videoSearch.items) {
|
||||||
const itemArtistId = item.artist?.id;
|
if (matchesArtistId(item) && !videoMap.has(item.id)) {
|
||||||
const matchesArtist =
|
|
||||||
itemArtistId === numericArtistId ||
|
|
||||||
(Array.isArray(item.artists) && item.artists.some((a) => a.id === numericArtistId));
|
|
||||||
|
|
||||||
if (matchesArtist && !videoMap.has(item.id)) {
|
|
||||||
videoMap.set(item.id, item);
|
videoMap.set(item.id, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1094,11 +1096,7 @@ export class LosslessAPI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const rawReleases = Array.from(albumMap.values()).filter((album) => {
|
const rawReleases = Array.from(albumMap.values()).filter(matchesArtistId);
|
||||||
const albumArtistId = album.artist?.id;
|
|
||||||
return albumArtistId === numericArtistId ||
|
|
||||||
(Array.isArray(album.artists) && album.artists.some((a) => a.id === numericArtistId));
|
|
||||||
});
|
|
||||||
const allReleases = this.deduplicateAlbums(rawReleases).sort(
|
const allReleases = this.deduplicateAlbums(rawReleases).sort(
|
||||||
(a, b) => new Date(b.releaseDate || 0) - new Date(a.releaseDate || 0)
|
(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 albums = allReleases.filter((a) => !eps.includes(a));
|
||||||
|
|
||||||
const topTracks = Array.from(trackMap.values())
|
const topTracks = Array.from(trackMap.values())
|
||||||
.filter((track) => {
|
.filter(matchesArtistId)
|
||||||
const trackArtistId = track.artist?.id;
|
|
||||||
return trackArtistId === numericArtistId ||
|
|
||||||
(Array.isArray(track.artists) && track.artists.some((a) => a.id === numericArtistId));
|
|
||||||
})
|
|
||||||
.sort((a, b) => (b.popularity || 0) - (a.popularity || 0))
|
.sort((a, b) => (b.popularity || 0) - (a.popularity || 0))
|
||||||
.slice(0, 15);
|
.slice(0, 15);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue