1
0

fix: skip null album entries in subsonic pagination

This commit is contained in:
2026-08-29 16:35:01 +02:00
parent dc63db54ba
commit 9b52039fde
2 changed files with 23 additions and 0 deletions

View File

@@ -85,6 +85,7 @@ export class SubsonicClient {
}) })
const list: any[] = envelope.albumList2?.album ?? [] const list: any[] = envelope.albumList2?.album ?? []
for (const a of list) { 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 ?? '' }) all.push({ id: String(a.id), title: a.name ?? a.title ?? '', artist: a.artist ?? '' })
} }
onProgress?.(all, all.length) onProgress?.(all, all.length)

View File

@@ -96,4 +96,26 @@ describe('SubsonicClient', () => {
await c.getAllAlbums((_albums, done) => progress.push(done)) await c.getAllAlbums((_albums, done) => progress.push(done))
expect(progress[progress.length - 1]!).toBe(503) 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' },
])
})
}) })