feat: subsonic library pagination
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user