mirror of
https://github.com/danbulant/Mangades
synced 2026-07-06 19:40:54 +00:00
better behaviour with multiple downloads
This commit is contained in:
parent
b1d1b36fbb
commit
a5a4cdbbed
1 changed files with 24 additions and 5 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
import { url } from "@roxi/routify/runtime/helpers";
|
import { page, url } from "@roxi/routify/runtime/helpers";
|
||||||
import { Zip, ZipPassThrough } from "fflate";
|
import { Zip, ZipPassThrough } from "fflate";
|
||||||
import { prepareEpub } from "../../util/generateEpub";
|
import { prepareEpub } from "../../util/generateEpub";
|
||||||
// import * as streamSaver from "streamsaver";
|
// import * as streamSaver from "streamsaver";
|
||||||
|
|
@ -12,6 +12,8 @@
|
||||||
$: mangaId = scoped.id;
|
$: mangaId = scoped.id;
|
||||||
var manga = scoped.manga;
|
var manga = scoped.manga;
|
||||||
$: manga = scoped.manga;
|
$: manga = scoped.manga;
|
||||||
|
var relationships = scoped.mangaRelationships;
|
||||||
|
$: relationships = scoped.mangaRelationships;
|
||||||
|
|
||||||
async function getMangaChapters(id) {
|
async function getMangaChapters(id) {
|
||||||
const data = await request("manga/" + id + "/feed?translatedLanguage[]=en");
|
const data = await request("manga/" + id + "/feed?translatedLanguage[]=en");
|
||||||
|
|
@ -24,10 +26,17 @@
|
||||||
|
|
||||||
console.log(manga);
|
console.log(manga);
|
||||||
console.log(chapters);
|
console.log(chapters);
|
||||||
|
console.log(relationships);
|
||||||
|
|
||||||
var progress = 0;
|
var progress = 0;
|
||||||
var state = "idle";
|
var state = "idle";
|
||||||
var text = "Choose a chapter to view online or download EPUB";
|
var text = "Choose a chapter to view online or download EPUB";
|
||||||
|
var pagesDone = 0;
|
||||||
|
var totalPages = 0;
|
||||||
|
|
||||||
|
$: progress = pagesDone / (totalPages || 1);
|
||||||
|
$: if(totalPages) text = `Saving page ${pagesDone + 1} of ${totalPages}`;
|
||||||
|
|
||||||
var enc = new TextEncoder();
|
var enc = new TextEncoder();
|
||||||
async function prepare(chapter) {
|
async function prepare(chapter) {
|
||||||
state = "active";
|
state = "active";
|
||||||
|
|
@ -44,6 +53,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
text = "Found " + URLs.length + " pages";
|
text = "Found " + URLs.length + " pages";
|
||||||
|
totalPages += URLs.length;
|
||||||
|
|
||||||
const file = streamSaver.createWriteStream(`${manga.title.en} ${chapter.data.attributes.chapter}.epub`, {
|
const file = streamSaver.createWriteStream(`${manga.title.en} ${chapter.data.attributes.chapter}.epub`, {
|
||||||
writableStrategy: undefined, // (optional)
|
writableStrategy: undefined, // (optional)
|
||||||
|
|
@ -59,8 +69,6 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
for(var i = 0; i < URLs.length; i++) {
|
for(var i = 0; i < URLs.length; i++) {
|
||||||
text = `Saving page ${i + 1} of ${URLs.length}`;
|
|
||||||
progress = (i + 1) / URLs.length;
|
|
||||||
const url = URLs[i];
|
const url = URLs[i];
|
||||||
const hash = hashes[i];
|
const hash = hashes[i];
|
||||||
const res = await fetch(url);
|
const res = await fetch(url);
|
||||||
|
|
@ -80,11 +88,22 @@
|
||||||
<img style="margin:auto;height:100%;" src="${hash}" />
|
<img style="margin:auto;height:100%;" src="${hash}" />
|
||||||
</body>
|
</body>
|
||||||
</html>`), true);
|
</html>`), true);
|
||||||
|
pagesDone++;
|
||||||
}
|
}
|
||||||
|
|
||||||
zip.end();
|
zip.end();
|
||||||
text = "Done!";
|
if(pagesDone === totalPages) {
|
||||||
state = "idle";
|
text = "Done!";
|
||||||
|
state = "idle";
|
||||||
|
pagesDone = 0;
|
||||||
|
totalPages = 0;
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
if(totalPages === 0) {
|
||||||
|
text = "Choose a chapter to view online or download EPUB";
|
||||||
|
}
|
||||||
|
}, 3000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue