--out-dir
This commit is contained in:
parent
527840e3ff
commit
de2644352d
4 changed files with 13 additions and 2 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
node_modules
|
||||
*.db
|
||||
dist
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import sqlite3 from "sqlite3";
|
||||
import { Database, open } from "sqlite";
|
||||
|
||||
export { Database };
|
||||
|
||||
export async function createDatabase(file: string): Promise<Database> {
|
||||
await fs.mkdir(path.dirname(file), { recursive: true });
|
||||
|
||||
const db = await open({
|
||||
filename: file,
|
||||
driver: sqlite3.cached.Database,
|
||||
|
|
7
main.ts
7
main.ts
|
@ -10,6 +10,10 @@ const options = {
|
|||
type: "string",
|
||||
default: "gadl.db",
|
||||
},
|
||||
"out-dir": {
|
||||
type: "string",
|
||||
default: "dist",
|
||||
},
|
||||
reset: {
|
||||
type: "boolean",
|
||||
async run() {
|
||||
|
@ -87,7 +91,8 @@ const options = {
|
|||
|
||||
const browser = await chromium.launch();
|
||||
const platform = createPlatform({ db, browser });
|
||||
await platform.download(args.values.download!, book);
|
||||
const dir = `${args.values["out-dir"]!}/${book.id}`;
|
||||
await platform.download(dir, book);
|
||||
},
|
||||
},
|
||||
help: {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import type { Book } from "../library";
|
||||
import { userAgent, type Browser, type BrowserContext } from "../browser";
|
||||
import type { Database } from "../database";
|
||||
|
@ -155,7 +156,8 @@ export function DmmBooks({ db, browser }: { db: Database; browser: Browser }) {
|
|||
const page = await ctx.newPage();
|
||||
|
||||
// TODO: --all
|
||||
// await fs.mkdir(dir);
|
||||
await fs.mkdir(path.dirname(dir), { recursive: true });
|
||||
await fs.mkdir(dir);
|
||||
await page.goto(book.readerUrl);
|
||||
|
||||
const files = await page.evaluate(getFiles);
|
||||
|
|
Loading…
Add table
Reference in a new issue