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]), Object.fromEntries([...mangaIdToDefaultDownloadSize, ...mangaIdToDownloadSize]),
) satisfies MangaIdToDownloadSize[]; ) satisfies MangaIdToDownloadSize[];
const chapterIdsToDownload = mangaIdToActualDownloadSize.flatMap(([mangaId, actualSize]) => { const chaptersToDownload = mangaIdToActualDownloadSize
const mangaChapters = mangaIdToChaptersToConsider[Number(mangaId)] ?? []; .flatMap(([mangaId, actualSize]) => {
const mangaChapters = mangaIdToChaptersToConsider[Number(mangaId)] ?? [];
if (!mangaChapters.length) { if (!mangaChapters.length) {
return []; return [];
} }
const shouldDownloadAll = actualSize === undefined; const shouldDownloadAll = actualSize === undefined;
if (shouldDownloadAll) { if (shouldDownloadAll) {
return mangaChapters; return mangaChapters;
} }
const uniqueMangaChapters = Chapters.removeDuplicates(mangaChapters[0], mangaChapters); const uniqueMangaChapters = Chapters.removeDuplicates(mangaChapters[0], mangaChapters);
const uniqueMangaChaptersToDownload = uniqueMangaChapters.slice(0, actualSize); 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 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> { static async deleteChapters(mangaIds: number[], disableConfirmation?: boolean): Promise<void> {