archive
This commit is contained in:
parent
c5ac70d317
commit
ffb9abcfeb
2 changed files with 37 additions and 37 deletions
20
library.ts
20
library.ts
|
@ -72,20 +72,21 @@ on conflict(reader_url)
|
||||||
|
|
||||||
return books;
|
return books;
|
||||||
},
|
},
|
||||||
async archive(dir: string) {
|
async archive(dir: string, book: Book) {
|
||||||
const bookDirs = await fs.readdir(dir, { withFileTypes: true });
|
const path = `${dir}/${book.id}`;
|
||||||
|
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(`${dir}/${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 +110,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, book);
|
||||||
}
|
}
|
||||||
|
|
||||||
await library.archive(args.values["out-dir"]!);
|
|
||||||
await browser.close();
|
await browser.close();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Reference in a new issue