mirror of
https://github.com/lifegpc/eh-downloader.git
synced 2026-06-06 05:38:44 +08:00
Fix utt can not handle Ctrl + C
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@
|
||||
config.json
|
||||
test/
|
||||
downloads/
|
||||
utt.lock
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { EhDb } from "./db.ts";
|
||||
import { asyncForEach } from "./utils.ts";
|
||||
|
||||
export type GHAuthor = {
|
||||
name: string;
|
||||
@@ -54,12 +55,18 @@ export async function load_eht_file(
|
||||
return JSON.parse(s);
|
||||
}
|
||||
|
||||
export function update_database_tag(db: EhDb, f: EHTTextFile) {
|
||||
export async function update_database_tag(
|
||||
db: EhDb,
|
||||
f: EHTTextFile,
|
||||
signal: AbortSignal,
|
||||
) {
|
||||
await Deno.writeTextFile("./utt.lock", "", { create: true, signal });
|
||||
for (const d of f.data) {
|
||||
Object.getOwnPropertyNames(d.data).forEach((name) => {
|
||||
await asyncForEach(Object.getOwnPropertyNames(d.data), async (name) => {
|
||||
const tag = `${d.namespace}:${name}`;
|
||||
const t = d.data[name];
|
||||
db.update_tags(tag, t.name, t.intro);
|
||||
await Deno.readTextFile("./utt.lock", { signal });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
5
main.ts
5
main.ts
@@ -3,7 +3,7 @@ import { load_settings } from "./config.ts";
|
||||
import { check_file_permissions } from "./permissons.ts";
|
||||
import { AlreadyClosedError, TaskManager } from "./task_manager.ts";
|
||||
import { ParsedUrl, parseUrl, UrlType } from "./url.ts";
|
||||
import { sure_dir } from "./utils.ts";
|
||||
import { sure_dir, try_remove_sync } from "./utils.ts";
|
||||
import { EhDb } from "./db.ts";
|
||||
import { load_eht_file, update_database_tag } from "./eh_translation.ts";
|
||||
import { get_abort_signal } from "./signal_handler.ts";
|
||||
@@ -94,10 +94,11 @@ async function update_tag_translation() {
|
||||
args._.length > 1 ? args._[1].toString() : undefined,
|
||||
signal,
|
||||
);
|
||||
update_database_tag(db, f);
|
||||
await update_database_tag(db, f, signal);
|
||||
} catch (e) {
|
||||
if (!signal.aborted) throw e;
|
||||
} finally {
|
||||
try_remove_sync("utt.lock");
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ export function add_exit_handler(m: TaskManager) {
|
||||
export function get_abort_signal(callback?: () => void): AbortSignal {
|
||||
const a = new AbortController();
|
||||
const handler = () => {
|
||||
console.log("Aborted.");
|
||||
a.abort();
|
||||
if (callback) callback();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user