archive
This commit is contained in:
parent
c5ac70d317
commit
53dd6c2b1f
2 changed files with 36 additions and 37 deletions
21
library.ts
21
library.ts
|
@ -72,20 +72,20 @@ on conflict(reader_url)
|
||||||
|
|
||||||
return books;
|
return books;
|
||||||
},
|
},
|
||||||
async archive(dir: string) {
|
async archive(path: string, outDir: string, book: Book) {
|
||||||
const bookDirs = await fs.readdir(dir, { withFileTypes: true });
|
const bookDir = await fs.stat(path);
|
||||||
|
|
||||||
for (const bookDir of bookDirs) {
|
|
||||||
if (!bookDir.isDirectory()) {
|
if (!bookDir.isDirectory()) {
|
||||||
continue;
|
throw new Error(`Not found: ${path}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const path = `${bookDir.path}/${bookDir.name}`;
|
const title = `${book.authors.join("、")}「${book.title}」`.replace(
|
||||||
const book = await this.get(bookDir.name);
|
/[/]/g,
|
||||||
const title = book
|
"%2F",
|
||||||
? `${book.authors.join("、")}「${book.title}」`.replace(/[/]/g, "%2F")
|
);
|
||||||
: bookDir.name;
|
|
||||||
const out = createWriteStream(`${dir}/${title}.cbz`);
|
const out = createWriteStream(`${outDir}/${title}.cbz`);
|
||||||
|
|
||||||
const zip = new Zip(function cb(err, data, final) {
|
const zip = new Zip(function cb(err, data, final) {
|
||||||
if (err) {
|
if (err) {
|
||||||
out.destroy(err);
|
out.destroy(err);
|
||||||
|
@ -109,7 +109,6 @@ on conflict(reader_url)
|
||||||
|
|
||||||
await stream.finished(out);
|
await stream.finished(out);
|
||||||
await fs.rm(path, { recursive: true });
|
await fs.rm(path, { recursive: true });
|
||||||
}
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
2
main.ts
2
main.ts
|
@ -126,9 +126,9 @@ const options = {
|
||||||
for (const book of books) {
|
for (const book of books) {
|
||||||
const dir = `${args.values["out-dir"]!}/${book.id}`;
|
const dir = `${args.values["out-dir"]!}/${book.id}`;
|
||||||
await platform.download(dir, book);
|
await platform.download(dir, book);
|
||||||
|
await library.archive(dir, args.values["out-dir"]!, book);
|
||||||
}
|
}
|
||||||
|
|
||||||
await library.archive(args.values["out-dir"]!);
|
|
||||||
await browser.close();
|
await browser.close();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Reference in a new issue