fix: page through all chapters when the API omits total
All checks were successful
deploy / test-backend (push) Successful in 44m20s
deploy / test-frontend (push) Successful in 11m3s
deploy / build-and-push (push) Successful in 13m53s
deploy / deploy (push) Successful in 20s

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:
MechaCat02
2026-07-11 16:24:49 +02:00
parent f8e53809d5
commit a44511983d
5 changed files with 25 additions and 5 deletions

View File

@@ -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;
}