From 3a116e938ec9dc4100aab309f3f017ed02ba54fc Mon Sep 17 00:00:00 2001 From: Kendall Garner <17521368+kgarner7@users.noreply.github.com> Date: Mon, 19 Feb 2024 10:09:05 -0800 Subject: [PATCH] omit song from similar list, handle subsonic error --- src/renderer/api/jellyfin/jellyfin-controller.ts | 8 +++++++- src/renderer/api/subsonic/subsonic-controller.ts | 14 +++++++++++--- src/renderer/api/subsonic/subsonic-types.ts | 8 +++++--- .../components/similar-songs-list.tsx | 2 +- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/renderer/api/jellyfin/jellyfin-controller.ts b/src/renderer/api/jellyfin/jellyfin-controller.ts index d795abc7..cddb0158 100644 --- a/src/renderer/api/jellyfin/jellyfin-controller.ts +++ b/src/renderer/api/jellyfin/jellyfin-controller.ts @@ -980,7 +980,13 @@ const getSimilarSongs = async (args: SimilarSongsArgs): Promise => { throw new Error('Failed to get similar songs'); } - return res.body.Items.map((song) => jfNormalize.song(song, apiClientProps.server, '')); + return res.body.Items.reduce((acc, song) => { + if (song.Id !== query.songId) { + acc.push(jfNormalize.song(song, apiClientProps.server, '')); + } + + return acc; + }, []); }; export const jfController = { diff --git a/src/renderer/api/subsonic/subsonic-controller.ts b/src/renderer/api/subsonic/subsonic-controller.ts index 4aa123a1..75e3435e 100644 --- a/src/renderer/api/subsonic/subsonic-controller.ts +++ b/src/renderer/api/subsonic/subsonic-controller.ts @@ -460,9 +460,17 @@ const getSimilarSongs = async (args: SimilarSongsArgs): Promise => { throw new Error('Failed to get similar songs'); } - return res.body.similarSongs.song.map((song) => - ssNormalize.song(song, apiClientProps.server, ''), - ); + if (!res.body.similarSongs) { + return []; + } + + return res.body.similarSongs.song.reduce((acc, song) => { + if (song.id !== query.songId) { + acc.push(ssNormalize.song(song, apiClientProps.server, '')); + } + + return acc; + }, []); }; export const ssController = { diff --git a/src/renderer/api/subsonic/subsonic-types.ts b/src/renderer/api/subsonic/subsonic-types.ts index b54b9eb1..a9ff3125 100644 --- a/src/renderer/api/subsonic/subsonic-types.ts +++ b/src/renderer/api/subsonic/subsonic-types.ts @@ -253,9 +253,11 @@ const similarSongsParameters = z.object({ }); const similarSongs = z.object({ - similarSongs: z.object({ - song: z.array(song), - }), + similarSongs: z + .object({ + song: z.array(song), + }) + .optional(), }); export const ssType = { diff --git a/src/renderer/features/similar-songs/components/similar-songs-list.tsx b/src/renderer/features/similar-songs/components/similar-songs-list.tsx index 3a1595db..1c1dc678 100644 --- a/src/renderer/features/similar-songs/components/similar-songs-list.tsx +++ b/src/renderer/features/similar-songs/components/similar-songs-list.tsx @@ -71,7 +71,7 @@ export const SimilarSongsList = ({ count, fullScreen, song }: SimilarSongsListPr deselectOnClickOutside={fullScreen} getRowId={(data) => data.data.uniqueId} rowBuffer={50} - rowData={songQuery.data} + rowData={songQuery.data ?? []} rowHeight={tableConfig.rowHeight || 40} onCellContextMenu={onCellContextMenu} onCellDoubleClicked={handleRowDoubleClick}