Ignore duplicated chapters for download limits
In case the next 5 chapters should get downloaded and they are all the same chapter from different scanlators, then the download actually only included 1 chapter. To fix this duplicated chapters are counted as 1 chapter
This commit is contained in:
@@ -305,6 +305,18 @@ export class Chapters {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the provided "uniqueChapters" plus their duplicates found in "allChapters"
|
||||||
|
*/
|
||||||
|
static addDuplicates<T extends ChapterScanlatorInfo & ChapterNumberInfo>(
|
||||||
|
uniqueChapters: T[],
|
||||||
|
allChapters: T[],
|
||||||
|
): T[] {
|
||||||
|
const chapterNumberToChapters = Object.groupBy(allChapters, ({ chapterNumber }) => chapterNumber);
|
||||||
|
|
||||||
|
return uniqueChapters.map(({ chapterNumber }) => chapterNumberToChapters[chapterNumber]!).flat();
|
||||||
|
}
|
||||||
|
|
||||||
static removeDuplicates<T extends ChapterScanlatorInfo & ChapterNumberInfo>(currentChapter: T, chapters: T[]): T[] {
|
static removeDuplicates<T extends ChapterScanlatorInfo & ChapterNumberInfo>(currentChapter: T, chapters: T[]): T[] {
|
||||||
const chapterNumberToChapters = Object.groupBy(chapters, ({ chapterNumber }) => chapterNumber);
|
const chapterNumberToChapters = Object.groupBy(chapters, ({ chapterNumber }) => chapterNumber);
|
||||||
|
|
||||||
|
|||||||
@@ -280,7 +280,23 @@ export class Mangas {
|
|||||||
) satisfies MangaIdToDownloadSize[];
|
) satisfies MangaIdToDownloadSize[];
|
||||||
|
|
||||||
const chapterIdsToDownload = mangaIdToActualDownloadSize
|
const chapterIdsToDownload = mangaIdToActualDownloadSize
|
||||||
.map(([mangaId, actualSize]) => mangaIdToChaptersToConsider[Number(mangaId)]!.slice(0, actualSize))
|
.map(([mangaId, actualSize]) => {
|
||||||
|
const mangaChapters = mangaIdToChaptersToConsider[Number(mangaId)]!;
|
||||||
|
|
||||||
|
if (!mangaChapters.length) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const shouldDownloadAll = actualSize === undefined;
|
||||||
|
if (shouldDownloadAll) {
|
||||||
|
return mangaChapters;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uniqueMangaChapters = Chapters.removeDuplicates(mangaChapters[0], mangaChapters);
|
||||||
|
const uniqueMangaChaptersToDownload = uniqueMangaChapters.slice(0, actualSize);
|
||||||
|
|
||||||
|
return Chapters.addDuplicates(uniqueMangaChaptersToDownload, mangaChapters);
|
||||||
|
})
|
||||||
.flat();
|
.flat();
|
||||||
|
|
||||||
if (!chapterIdsToDownload.length) {
|
if (!chapterIdsToDownload.length) {
|
||||||
|
|||||||
@@ -3120,7 +3120,7 @@ export type GetMangasChapterIdsWithStateQueryVariables = Exact<{
|
|||||||
}>;
|
}>;
|
||||||
|
|
||||||
|
|
||||||
export type GetMangasChapterIdsWithStateQuery = { __typename?: 'Query', chapters: { __typename?: 'ChapterNodeList', nodes: Array<{ __typename?: 'ChapterType', id: number, isDownloaded: boolean, isRead: boolean, isBookmarked: boolean, mangaId: number }> } };
|
export type GetMangasChapterIdsWithStateQuery = { __typename?: 'Query', chapters: { __typename?: 'ChapterNodeList', nodes: Array<{ __typename?: 'ChapterType', id: number, isDownloaded: boolean, isRead: boolean, isBookmarked: boolean, mangaId: number, scanlator?: string | null, chapterNumber: number }> } };
|
||||||
|
|
||||||
export type GetDownloadStatusQueryVariables = Exact<{ [key: string]: never; }>;
|
export type GetDownloadStatusQueryVariables = Exact<{ [key: string]: never; }>;
|
||||||
|
|
||||||
|
|||||||
@@ -73,6 +73,8 @@ export const GET_MANGAS_CHAPTER_IDS_WITH_STATE = gql`
|
|||||||
isRead
|
isRead
|
||||||
isBookmarked
|
isBookmarked
|
||||||
mangaId
|
mangaId
|
||||||
|
scanlator
|
||||||
|
chapterNumber
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user