Fix TypeError in Mangas::downloadChapters

In case a manga was completely downloaded, the grouped chapters did not contain a list for the specific manga id, resulting in an TypeError due to trying to use the array as if it was not undefined
This commit is contained in:
schroda
2024-04-29 22:59:40 +02:00
parent 0f16429c14
commit 5ab921aba7
2 changed files with 6 additions and 7 deletions

View File

@@ -314,7 +314,9 @@ export class Chapters {
): T[] {
const chapterNumberToChapters = Object.groupBy(allChapters, ({ chapterNumber }) => chapterNumber);
return uniqueChapters.map(({ chapterNumber }) => chapterNumberToChapters[chapterNumber]!).flat();
return uniqueChapters
.map((uniqueChapter) => chapterNumberToChapters[uniqueChapter.chapterNumber] ?? [uniqueChapter])
.flat();
}
static removeDuplicates<T extends ChapterScanlatorInfo & ChapterNumberInfo>(currentChapter: T, chapters: T[]): T[] {