Prevent enqueuing already queued chapter downloads

Didn't break anything, but creates unnecessary requests as well as misleading toasts
This commit is contained in:
schroda
2026-05-05 00:55:45 +02:00
parent 7b20f08f51
commit 4f7fb68e42

View File

@@ -219,29 +219,31 @@ export class Mangas {
Object.fromEntries([...mangaIdToDefaultDownloadSize, ...mangaIdToDownloadSize]),
) satisfies MangaIdToDownloadSize[];
const chapterIdsToDownload = mangaIdToActualDownloadSize.flatMap(([mangaId, actualSize]) => {
const mangaChapters = mangaIdToChaptersToConsider[Number(mangaId)] ?? [];
const chaptersToDownload = mangaIdToActualDownloadSize
.flatMap(([mangaId, actualSize]) => {
const mangaChapters = mangaIdToChaptersToConsider[Number(mangaId)] ?? [];
if (!mangaChapters.length) {
return [];
}
if (!mangaChapters.length) {
return [];
}
const shouldDownloadAll = actualSize === undefined;
if (shouldDownloadAll) {
return mangaChapters;
}
const shouldDownloadAll = actualSize === undefined;
if (shouldDownloadAll) {
return mangaChapters;
}
const uniqueMangaChapters = Chapters.removeDuplicates(mangaChapters[0], mangaChapters);
const uniqueMangaChaptersToDownload = uniqueMangaChapters.slice(0, actualSize);
const uniqueMangaChapters = Chapters.removeDuplicates(mangaChapters[0], mangaChapters);
const uniqueMangaChaptersToDownload = uniqueMangaChapters.slice(0, actualSize);
return Chapters.addDuplicates(uniqueMangaChaptersToDownload, mangaChapters);
});
return Chapters.addDuplicates(uniqueMangaChaptersToDownload, mangaChapters);
})
.filter(Chapters.isDownloadable);
if (!chapterIdsToDownload.length) {
if (!chaptersToDownload.length) {
return Promise.resolve();
}
return Chapters.download(Chapters.getIds(chapterIdsToDownload), disableConfirmation);
return Chapters.download(Chapters.getIds(chaptersToDownload), disableConfirmation);
}
static async deleteChapters(mangaIds: number[], disableConfirmation?: boolean): Promise<void> {