mirror of
https://github.com/lifegpc/eh-downloader.git
synced 2026-06-06 05:38:44 +08:00
Make sure clean is worked
This commit is contained in:
9
db.ts
9
db.ts
@@ -90,13 +90,15 @@ export class EhDb {
|
||||
flock_enabled: boolean = eval('typeof Deno.flock !== "undefined"');
|
||||
file: Deno.FsFile | undefined;
|
||||
_exist_table: Set<string> = new Set();
|
||||
#lock_file: string | undefined;
|
||||
readonly version = new SemVer("1.0.0-0");
|
||||
constructor(base_path: string) {
|
||||
this.db = new DB(join(base_path, "data.db"));
|
||||
this.db.execute("PRAGMA main.locking_mode=EXCLUSIVE;");
|
||||
if (!this._check_database()) this._create_table();
|
||||
if (this.flock_enabled) {
|
||||
this.file = Deno.openSync(join(base_path, "db.lock"), {
|
||||
this.#lock_file = join(base_path, "db.lock");
|
||||
this.file = Deno.openSync(this.#lock_file, {
|
||||
create: true,
|
||||
write: true,
|
||||
});
|
||||
@@ -200,7 +202,10 @@ export class EhDb {
|
||||
}
|
||||
close() {
|
||||
this.db.close();
|
||||
if (this.file) this.file.close();
|
||||
if (this.file) {
|
||||
this.file.close();
|
||||
if (this.#lock_file) Deno.remove(this.#lock_file);
|
||||
}
|
||||
}
|
||||
async commit() {
|
||||
while (1) {
|
||||
|
||||
32
main.ts
32
main.ts
@@ -45,22 +45,32 @@ if (!check_file_permissions(settings.base)) {
|
||||
}
|
||||
async function download() {
|
||||
const manager = new TaskManager(settings);
|
||||
const urls: ParsedUrl[] = [];
|
||||
for (const i of args._.slice(1)) {
|
||||
const r = parseUrl(i.toString());
|
||||
if (r) urls.push(r);
|
||||
}
|
||||
for (const u of urls) {
|
||||
if (u.type == UrlType.Gallery || u.type == UrlType.MPV) {
|
||||
await manager.add_download_task(u.gid, u.token);
|
||||
try {
|
||||
const urls: ParsedUrl[] = [];
|
||||
for (const i of args._.slice(1)) {
|
||||
const r = parseUrl(i.toString());
|
||||
if (r) urls.push(r);
|
||||
}
|
||||
for (const u of urls) {
|
||||
if (u.type == UrlType.Gallery || u.type == UrlType.MPV) {
|
||||
await manager.add_download_task(u.gid, u.token);
|
||||
}
|
||||
}
|
||||
if (args.add_only) {
|
||||
return;
|
||||
}
|
||||
await manager.run();
|
||||
} finally {
|
||||
manager.close();
|
||||
}
|
||||
if (args.add_only) return;
|
||||
await manager.run();
|
||||
}
|
||||
async function run() {
|
||||
const manager = new TaskManager(settings);
|
||||
await manager.run();
|
||||
try {
|
||||
await manager.run();
|
||||
} finally {
|
||||
manager.close();
|
||||
}
|
||||
}
|
||||
async function main() {
|
||||
await sure_dir(settings.base);
|
||||
|
||||
@@ -67,6 +67,9 @@ export class TaskManager {
|
||||
this.running_tasks.delete(id);
|
||||
}
|
||||
}
|
||||
close() {
|
||||
this.db.close();
|
||||
}
|
||||
async run() {
|
||||
while (1) {
|
||||
await this.check_running_tasks();
|
||||
|
||||
Reference in New Issue
Block a user