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[] {

View File

@@ -264,11 +264,8 @@ export class Mangas {
const mangaIdToUnReadDownloadedChapters = Object.groupBy(unReadDownloadedChapters, ({ mangaId }) => mangaId);
const mangaIdToDownloadSize = Object.entries(mangaIdToUnReadDownloadedChapters).map(
([mangaId, downloadedChapters]) => {
const downloadAheadSize = Math.max(
0,
(size ?? downloadedChapters!.length) - downloadedChapters!.length,
);
([mangaId, downloadedChapters = []]) => {
const downloadAheadSize = Math.max(0, (size ?? downloadedChapters.length) - downloadedChapters.length);
const actualSize = downloadAhead ? downloadAheadSize : size;
return [mangaId, actualSize];
@@ -281,7 +278,7 @@ export class Mangas {
const chapterIdsToDownload = mangaIdToActualDownloadSize
.map(([mangaId, actualSize]) => {
const mangaChapters = mangaIdToChaptersToConsider[Number(mangaId)]!;
const mangaChapters = mangaIdToChaptersToConsider[Number(mangaId)] ?? [];
if (!mangaChapters.length) {
return [];