This commit is contained in:
2023-05-21 13:58:13 +08:00
parent 96b62e94cc
commit 1dd7c21bb6
7 changed files with 23 additions and 8 deletions

View File

@@ -8,5 +8,7 @@
// Maximum task count
"max_task_count": 1,
// Fetch page data from Multi-Page Viewer
"mpv": false
"mpv": false,
// The folder that to store database.
"db_path": "./downloads"
}

View File

@@ -44,6 +44,9 @@ export class Config {
get cookies() {
return this._return_string("cookies");
}
get db_path() {
return this._return_string("db_path");
}
get ua() {
return this._return_string("ua");
}

6
db.ts
View File

@@ -3,7 +3,7 @@ import { SemVer } from "std/semver/mod.ts";
import { join } from "std/path/mod.ts";
import { SqliteError } from "sqlite/mod.ts";
import { Status } from "sqlite/src/constants.ts";
import { sleep } from "./utils.ts";
import { sleep, sure_dir_sync } from "./utils.ts";
import { Task, TaskType } from "./task.ts";
type SqliteMaster = {
@@ -157,7 +157,9 @@ export class EhDb {
#_tags: Map<string, number> | undefined;
readonly version = new SemVer("1.0.0-1");
constructor(base_path: string) {
this.db = new DB(join(base_path, "data.db"));
const db_path = join(base_path, "data.db");
sure_dir_sync(base_path);
this.db = new DB(db_path);
this.db.execute("PRAGMA main.locking_mode=EXCLUSIVE;");
if (!this.#check_database()) this.#create_table();
if (this.#flock_enabled) {

View File

@@ -8,7 +8,8 @@
"dev": "deno run --watch main.ts",
"test": "deno test --allow-read=./config.json,./test --allow-net --allow-write=./test --allow-run=tasklist.exe --unstable",
"run": "deno run --allow-read=./config.json,./downloads --allow-write=./downloads --allow-run=tasklist.exe --allow-net --unstable",
"compile": "deno compile --allow-read=./config.json,./downloads --allow-write=./downloads --allow-run=tasklist.exe --allow-net --unstable"
"compile": "deno compile --allow-read=./config.json,./downloads --allow-write=./downloads --allow-run=tasklist.exe --allow-net --unstable",
"compile_full": "deno compile --allow-read --allow-write --allow-run=tasklist.exe --allow-net --unstable"
},
"fmt": {
"indentWidth": 4,

View File

@@ -81,16 +81,17 @@ async function run() {
}
}
function optimize() {
const db = new EhDb(settings.base);
const db = new EhDb(settings.db_path || settings.base);
db.optimize();
db.close();
}
async function update_tag_translation() {
const db = new EhDb(settings.base);
const db = new EhDb(settings.db_path || settings.base);
const f = await load_eht_file(
args._.length > 1 ? args._[1].toString() : undefined,
);
update_database_tag(db, f);
db.close();
}
async function main() {
await sure_dir(settings.base);

View File

@@ -20,7 +20,7 @@ export class TaskManager {
constructor(cfg: Config) {
this.cfg = cfg;
this.client = new Client(cfg);
this.db = new EhDb(cfg.base);
this.db = new EhDb(cfg.db_path || cfg.base);
this.running_tasks = new Map();
this.max_task_count = cfg.max_task_count;
add_exit_handler(this);

View File

@@ -1,4 +1,4 @@
import { exists } from "std/fs/exists.ts";
import { exists, existsSync } from "std/fs/exists.ts";
import { initParser } from "deno_dom/deno-dom-wasm-noinit.ts";
export function sleep(time: number): Promise<undefined> {
@@ -15,6 +15,12 @@ export async function sure_dir(f = "./test") {
}
}
export function sure_dir_sync(f = "./test") {
if (!existsSync(f)) {
Deno.mkdirSync(f, { "recursive": true });
}
}
export enum PromiseStatus {
Pending,
Fulfilled,