1
0

feat: subsonic library pagination

This commit is contained in:
2026-08-29 16:31:08 +02:00
parent 72f3fc8436
commit dc63db54ba
2 changed files with 120 additions and 0 deletions

View File

@@ -71,4 +71,25 @@ export class SubsonicClient {
async ping(): Promise<void> {
await this.request('ping')
}
async getAllAlbums(
onProgress?: (albums: SubsonicAlbum[], done: number) => void
): Promise<SubsonicAlbum[]> {
const all: SubsonicAlbum[] = []
const pageSize = 500
for (let offset = 0; ; offset += pageSize) {
const envelope = await this.request('getAlbumList2', {
type: 'alphabeticalByName',
size: String(pageSize),
offset: String(offset),
})
const list: any[] = envelope.albumList2?.album ?? []
for (const a of list) {
all.push({ id: String(a.id), title: a.name ?? a.title ?? '', artist: a.artist ?? '' })
}
onProgress?.(all, all.length)
if (list.length < pageSize || all.length > 20000) break
}
return all
}
}