fix: reader loads the full chapter list for prev/next and the dropdown

The reader fetched only the first 200 chapters, so a deep chapter (#250) fell
outside the window and its prev/next chevrons resolved to null — a dead end —
and the chapter dropdown was truncated. Add listAllChapters, which pages
through the API's 200-row cap, and use it in the reader loader.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
MechaCat02
2026-07-11 15:02:44 +02:00
parent 69a9309c54
commit c308eb3eac
4 changed files with 55 additions and 9 deletions

View File

@@ -40,6 +40,28 @@ export async function listChapters(
);
}
/**
* Every chapter of a manga, in display order, paging through the API (which
* clamps `limit` to 200 per request). The reader needs the complete list so
* prev/next navigation and the chapter dropdown work for a deep chapter — a
* single 200-row window dead-ended chapter #250 with null neighbours.
*/
export async function listAllChapters(mangaId: string): Promise<Chapter[]> {
const PAGE = 200;
const all: Chapter[] = [];
let offset = 0;
// Hard iteration cap (200 * 100 = 20k chapters) so a bad `total` can never
// spin forever.
for (let i = 0; i < 100; i++) {
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;
}
return all;
}
export async function getChapter(mangaId: string, chapterId: string): Promise<Chapter> {
return request<Chapter>(
`/v1/mangas/${encodeURIComponent(mangaId)}/chapters/${encodeURIComponent(chapterId)}`