Slice chapter list correctly for downloads

Chapters are sorted in desc order and thus, the oldest chapters are at the end of the list.
Thus, the chapters to download need to be taken from the end instead from the start
This commit is contained in:
schroda
2025-07-08 22:07:17 +02:00
parent 1c9d62659f
commit 8783956fbc

View File

@@ -82,11 +82,11 @@ const handleDownload = async (
const chapters = await requestManager.getChapters<GetChaptersMangaQuery, GetChaptersMangaQueryVariables>(
GET_CHAPTERS_MANGA,
{
// Align conditions/filters with the query from ChapterList to potentially be able to reuse the cache
condition: { mangaId: Number(mangaId) },
order: [{ by: ChapterOrderBy.SourceOrder, byType: SortOrder.Desc }],
},
).response;
const filteredChapters = filterChapters(chapters.data.chapters.nodes, meta);
const chaptersToDownload = filteredChapters
.filter((chapter) => {
@@ -96,7 +96,7 @@ const handleDownload = async (
return !chapter.isDownloaded;
})
.slice(0, size);
.slice(-(size ?? 0));
if (!chaptersToDownload.length) {
return;