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; 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); const bookDir = await fs.stat(path);
if (!bookDir.isDirectory()) { if (!bookDir.isDirectory()) {
throw new Error(`Not found: ${path}`); throw new Error(`Not found: ${path}`);
} }
const title = `${book.authors.join("、")}${book.title}`.replace( const title = `${book.authors
/[/]/g, .slice(0, opts.outAuthorsLimit)
"%2F", .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) { const zip = new Zip(function cb(err, data, final) {
if (err) { if (err) {

View file

@ -13,6 +13,10 @@ const options = {
type: "string", type: "string",
default: "dist", default: "dist",
}, },
"out-authors-limit": {
type: "string",
default: "3",
},
login: { login: {
type: "boolean", type: "boolean",
async run() { async run() {
@ -125,7 +129,10 @@ const options = {
const platform = createPlatform({ db, browser }); const platform = createPlatform({ db, browser });
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(dir, book, {
outDir: args.values["out-dir"]!,
outAuthorsLimit: Number(args.values["out-authors-limit"]!),
});
await browser.close(); await browser.close();
} }
}, },