allow downloading selected chapters in separate files

This commit is contained in:
lhk1337 2022-01-23 17:54:52 +01:00
parent b772eda4d1
commit 7c46ff0f13

View file

@ -83,15 +83,10 @@
cbz: CBZGenerator
}
async function downloadSingle(chapter) {
const file = streamSaver.createWriteStream(`${manga.title.en} ${chapter.attributes.chapter}.${format}`, {
writableStrategy: undefined, // (optional)
readableStrategy: undefined, // (optional)
});
const generator = new generators[format]({
function createGenerator(chapter, file) {
return new generators[format]({
file,
id: chapter.id,
id: window.location.toString() + "-" + chapter.id,
language: chapter.attributes.translatedLanguage,
updatedAt: chapter.attributes.updatedAt,
title: manga.title.en,
@ -102,6 +97,14 @@
volume: chapter.attributes.volume
}]
});
}
async function downloadSingle(chapter) {
const file = streamSaver.createWriteStream(`${manga.title.en} ${chapter.attributes.chapter}.${format}`, {
writableStrategy: undefined, // (optional)
readableStrategy: undefined, // (optional)
});
const generator = createGenerator(chapter, file)
console.log(generator);
queue.push(generator);
@ -154,6 +157,30 @@
selected = [];
processQueue();
}
function downloadSeparate() {
selected.sort((a, b) => a.attributes.chapter - b.attributes.chapter);
if(!selected.length) return;
if(selected.length === 1) {
downloadSingle(selected.shift());
selected = [];
return;
}
for (const chapter of selected) {
const file = streamSaver.createWriteStream(`${manga.title.en} ${chapter.attributes.chapter}.${format}`, {
writableStrategy: undefined, // (optional)
readableStrategy: undefined, // (optional)
});
const generator = createGenerator(chapter, file)
console.log(generator);
queue.push(generator);
}
selected = [];
processQueue();
}
/**
* @param {BeforeUnloadEvent} e
@ -230,6 +257,7 @@
<option value="epub"><b>.epub</b> Electronic publication</option>
</select>
<button disabled={!selected.length} on:click={downloadMulti}>Download</button>
<button disabled={!selected.length} on:click={downloadSeparate}>Download Separate</button>
</div>
<div class="flex">