From 00675bbbd3e72e8e710d8aa9b73b491e65153d40 Mon Sep 17 00:00:00 2001 From: Lei Nelissen Date: Sun, 26 May 2024 00:23:29 +0200 Subject: [PATCH] fix: do extra checks for album ids in --- src/store/music/actions.ts | 1 + src/utility/JellyfinApi.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/store/music/actions.ts b/src/store/music/actions.ts index 87728272..8fb23d0a 100644 --- a/src/store/music/actions.ts +++ b/src/store/music/actions.ts @@ -71,6 +71,7 @@ AsyncThunkAPI const albums = await Promise.all(results.filter((item) => ( !state.music.albums.ids.includes(item.Type === 'MusicAlbum' ? item.Id : item.AlbumId) + && (item.Type === 'Audio' ? item.AlbumId : true) )).map(async (item) => { if (item.Type === 'MusicAlbum') { return item; diff --git a/src/utility/JellyfinApi.ts b/src/utility/JellyfinApi.ts index ad0752b4..ccd95044 100644 --- a/src/utility/JellyfinApi.ts +++ b/src/utility/JellyfinApi.ts @@ -214,9 +214,13 @@ export async function searchItem( }).toString(); const results = await fetch(`${credentials?.uri}/Users/${credentials?.user_id}/Items?${params}`, config) - .then(response => response.json()); + .then(response => response.json() as Promise<{ Items: (Album | AlbumTrack)[] }>); - return results.Items; + return results.Items + .filter((item) => ( + // GUARD: Ensure that we're either dealing with an album or a track from an album. + item.Type === 'MusicAlbum' || (item.Type === 'Audio' && item.AlbumId) + )); } const playlistOptions = {