diff --git a/server/src/subsonic.ts b/server/src/subsonic.ts index 06261b9..315a0e2 100644 --- a/server/src/subsonic.ts +++ b/server/src/subsonic.ts @@ -85,6 +85,7 @@ export class SubsonicClient { }) const list: any[] = envelope.albumList2?.album ?? [] for (const a of list) { + if (!a || a.id == null) continue all.push({ id: String(a.id), title: a.name ?? a.title ?? '', artist: a.artist ?? '' }) } onProgress?.(all, all.length) diff --git a/server/test/subsonic.test.ts b/server/test/subsonic.test.ts index 6d5c324..a99514e 100644 --- a/server/test/subsonic.test.ts +++ b/server/test/subsonic.test.ts @@ -96,4 +96,26 @@ describe('SubsonicClient', () => { await c.getAllAlbums((_albums, done) => progress.push(done)) expect(progress[progress.length - 1]!).toBe(503) }) + + it('getAllAlbums skips null album entries', async () => { + const c = new SubsonicClient({ + url: 'http://x', + username: 'sam', + password: 'pass', + fetchImpl: (async () => + subsonicResponse({ + 'subsonic-response': { + status: 'ok', + albumList2: { + album: [{ id: 1, name: 'Album 1', artist: 'Artist 0' }, null, { id: 2, name: 'Album 2', artist: 'Artist 0' }], + }, + }, + })) as typeof fetch, + }) + const albums = await c.getAllAlbums() + expect(albums).toEqual([ + { id: '1', title: 'Album 1', artist: 'Artist 0' }, + { id: '2', title: 'Album 2', artist: 'Artist 0' }, + ]) + }) })