This commit is contained in:
Nebel 2023-11-23 10:24:08 +09:00
parent c5ac70d317
commit 53dd6c2b1f
Signed by: nebel
GPG key ID: 79807D08C6EF6460
2 changed files with 36 additions and 37 deletions

View file

@ -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 });
}
}, },
}; };
} }

View file

@ -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();
}, },
}, },