diff --git a/src/renderer/api/jellyfin/jellyfin-controller.ts b/src/renderer/api/jellyfin/jellyfin-controller.ts index 2958dad0..ff07ebc5 100644 --- a/src/renderer/api/jellyfin/jellyfin-controller.ts +++ b/src/renderer/api/jellyfin/jellyfin-controller.ts @@ -63,6 +63,7 @@ import { JFSongListSort, JFSortOrder } from '/@/renderer/api/jellyfin.types'; import isElectron from 'is-electron'; import { ServerFeature } from '/@/renderer/api/features-types'; import { VersionInfo, getFeatures } from '/@/renderer/api/utils'; +import chunk from 'lodash/chunk'; const formatCommaDelimitedString = (value: string[]) => { return value.join(','); @@ -473,6 +474,11 @@ const getSongList = async (args: SongListArgs): Promise => { }; }; +// Limit the query to 50 at a time to be *extremely* conservative on the +// length of the full URL, since the ids are part of the query string and +// not the POST body +const MAX_ITEMS_PER_PLAYLIST_ADD = 50; + const addToPlaylist = async (args: AddToPlaylistArgs): Promise => { const { query, body, apiClientProps } = args; @@ -480,19 +486,23 @@ const addToPlaylist = async (args: AddToPlaylistArgs): Promise => { const { query, apiClientProps } = args; - const res = await jfApiClient(apiClientProps).removeFromPlaylist({ - body: null, - params: { - id: query.id, - }, - query: { - EntryIds: query.songId, - }, - }); + const chunks = chunk(query.songId, MAX_ITEMS_PER_PLAYLIST_ADD); - if (res.status !== 204) { - throw new Error('Failed to remove from playlist'); + for (const chunk of chunks) { + const res = await jfApiClient(apiClientProps).removeFromPlaylist({ + body: null, + params: { + id: query.id, + }, + query: { + EntryIds: chunk.join(','), + }, + }); + + if (res.status !== 204) { + throw new Error('Failed to remove from playlist'); + } } return null; diff --git a/src/renderer/api/jellyfin/jellyfin-types.ts b/src/renderer/api/jellyfin/jellyfin-types.ts index 3790a21d..69117215 100644 --- a/src/renderer/api/jellyfin/jellyfin-types.ts +++ b/src/renderer/api/jellyfin/jellyfin-types.ts @@ -609,14 +609,14 @@ const addToPlaylist = z.object({ }); const addToPlaylistParameters = z.object({ - Ids: z.array(z.string()), + Ids: z.string(), UserId: z.string(), }); const removeFromPlaylist = z.null(); const removeFromPlaylistParameters = z.object({ - EntryIds: z.array(z.string()), + EntryIds: z.string(), }); const deletePlaylist = z.null();