fix: page through all chapters when the API omits total
listAllChapters used `page.total ?? all.length` as the loop bound. The /chapters endpoint always returns `total: null`, so a full 200-row first page broke the loop immediately — the reader dead-ended past chapter 200. Stop on a short page instead; only trust `total` when actually reported. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -56,8 +56,11 @@ export async function listAllChapters(mangaId: string): Promise<Chapter[]> {
|
||||
const { items, page } = await listChapters(mangaId, { limit: PAGE, offset });
|
||||
all.push(...items);
|
||||
offset += items.length;
|
||||
const total = page.total ?? all.length;
|
||||
if (items.length < PAGE || all.length >= total) break;
|
||||
// A short page is the only reliable end-of-list signal: the /chapters
|
||||
// endpoint returns `total: null`, so we can't infer completion from it.
|
||||
// Only stop early on `total` when the API actually reports one.
|
||||
if (items.length < PAGE) break;
|
||||
if (page.total != null && all.length >= page.total) break;
|
||||
}
|
||||
return all;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user