--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
|
node_modules
|
||||||
*.db
|
*.db
|
||||||
|
dist
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
import fs from "node:fs/promises";
|
import fs from "node:fs/promises";
|
||||||
|
import path from "node:path";
|
||||||
import sqlite3 from "sqlite3";
|
import sqlite3 from "sqlite3";
|
||||||
import { Database, open } from "sqlite";
|
import { Database, open } from "sqlite";
|
||||||
|
|
||||||
export { Database };
|
export { Database };
|
||||||
|
|
||||||
export async function createDatabase(file: string): Promise<Database> {
|
export async function createDatabase(file: string): Promise<Database> {
|
||||||
|
await fs.mkdir(path.dirname(file), { recursive: true });
|
||||||
|
|
||||||
const db = await open({
|
const db = await open({
|
||||||
filename: file,
|
filename: file,
|
||||||
driver: sqlite3.cached.Database,
|
driver: sqlite3.cached.Database,
|
||||||
|
|
7
main.ts
7
main.ts
|
@ -10,6 +10,10 @@ const options = {
|
||||||
type: "string",
|
type: "string",
|
||||||
default: "gadl.db",
|
default: "gadl.db",
|
||||||
},
|
},
|
||||||
|
"out-dir": {
|
||||||
|
type: "string",
|
||||||
|
default: "dist",
|
||||||
|
},
|
||||||
reset: {
|
reset: {
|
||||||
type: "boolean",
|
type: "boolean",
|
||||||
async run() {
|
async run() {
|
||||||
|
@ -87,7 +91,8 @@ const options = {
|
||||||
|
|
||||||
const browser = await chromium.launch();
|
const browser = await chromium.launch();
|
||||||
const platform = createPlatform({ db, browser });
|
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: {
|
help: {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import fs from "node:fs/promises";
|
import fs from "node:fs/promises";
|
||||||
|
import path from "node:path";
|
||||||
import type { Book } from "../library";
|
import type { Book } from "../library";
|
||||||
import { userAgent, type Browser, type BrowserContext } from "../browser";
|
import { userAgent, type Browser, type BrowserContext } from "../browser";
|
||||||
import type { Database } from "../database";
|
import type { Database } from "../database";
|
||||||
|
@ -155,7 +156,8 @@ export function DmmBooks({ db, browser }: { db: Database; browser: Browser }) {
|
||||||
const page = await ctx.newPage();
|
const page = await ctx.newPage();
|
||||||
|
|
||||||
// TODO: --all
|
// TODO: --all
|
||||||
// await fs.mkdir(dir);
|
await fs.mkdir(path.dirname(dir), { recursive: true });
|
||||||
|
await fs.mkdir(dir);
|
||||||
await page.goto(book.readerUrl);
|
await page.goto(book.readerUrl);
|
||||||
|
|
||||||
const files = await page.evaluate(getFiles);
|
const files = await page.evaluate(getFiles);
|
||||||
|
|
Loading…
Add table
Reference in a new issue