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:
@@ -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[] {
|
||||
|
||||
@@ -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 [];
|
||||
|
||||
Reference in New Issue
Block a user