fixed error: ENAMETOOLONG: name too long

This commit is contained in:
Nebel 2023-12-02 15:56:24 +09:00
parent bbcd9edb49
commit 16eb73bfdb
Signed by: nebel
GPG key ID: 79807D08C6EF6460
2 changed files with 20 additions and 7 deletions

View file

@ -72,19 +72,25 @@ on conflict(reader_url)
return books;
},
async archive(path: string, outDir: string, book: Book) {
async archive(
path: string,
book: Book,
opts: {
outDir: string;
outAuthorsLimit: number;
},
) {
const bookDir = await fs.stat(path);
if (!bookDir.isDirectory()) {
throw new Error(`Not found: ${path}`);
}
const title = `${book.authors.join("、")}${book.title}`.replace(
/[/]/g,
"%2F",
);
const title = `${book.authors
.slice(0, opts.outAuthorsLimit)
.join("、")}${book.title}`.replace(/[/]/g, "%2F");
const out = createWriteStream(`${outDir}/${title}.cbz`);
const out = createWriteStream(`${opts.outDir}/${title}.cbz`);
const zip = new Zip(function cb(err, data, final) {
if (err) {

View file

@ -13,6 +13,10 @@ const options = {
type: "string",
default: "dist",
},
"out-authors-limit": {
type: "string",
default: "3",
},
login: {
type: "boolean",
async run() {
@ -125,7 +129,10 @@ const options = {
const platform = createPlatform({ db, browser });
const dir = `${args.values["out-dir"]!}/${book.id}`;
await platform.download(dir, book);
await library.archive(dir, args.values["out-dir"]!, book);
await library.archive(dir, book, {
outDir: args.values["out-dir"]!,
outAuthorsLimit: Number(args.values["out-authors-limit"]!),
});
await browser.close();
}
},