mirror of
https://github.com/lifegpc/eh-downloader.git
synced 2026-07-08 01:31:00 +08:00
Fix /api/exit can not exit
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
"tasks": {
|
||||
"cache": "deno cache main.ts server-dev.ts",
|
||||
"server-dev": "deno run -A --unstable \"--watch=static/*.css,static/*.ts,static/*/,routes/,translation/\" server-dev.ts",
|
||||
"server": "deno run -A --unstable server-run.ts",
|
||||
"test": "deno test --allow-read=./ --allow-net --allow-write=./ --allow-run=tasklist.exe --unstable",
|
||||
"run": "deno run --allow-read=./ --allow-write=./ --allow-run=tasklist.exe --allow-env=DENO_DEPLOYMENT_ID --allow-net --unstable",
|
||||
"compile": "deno compile --allow-read=./ --allow-write=./ --allow-run=tasklist.exe --allow-env=DENO_DEPLOYMENT_ID --allow-net --unstable",
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
import { parse_bool } from "../../server/parse_form.ts";
|
||||
import { get_task_manager } from "../../server.ts";
|
||||
import { ExitTarget } from "../../signal_handler.ts";
|
||||
import { AlreadyClosedError } from "../../task_manager.ts";
|
||||
|
||||
export const handler: Handlers = {
|
||||
async POST(req, _ctx) {
|
||||
@@ -11,7 +13,7 @@ export const handler: Handlers = {
|
||||
} catch (_) {
|
||||
null;
|
||||
}
|
||||
setTimeout(async () => {
|
||||
const h = async () => {
|
||||
const m = get_task_manager();
|
||||
const aborted = m.aborted;
|
||||
m.abort();
|
||||
@@ -20,8 +22,11 @@ export const handler: Handlers = {
|
||||
}
|
||||
if (aborted) return;
|
||||
await m.waiting_unfinished_task();
|
||||
ExitTarget.dispatchEvent(new Event("close"));
|
||||
m.close();
|
||||
}, 1);
|
||||
throw new AlreadyClosedError();
|
||||
};
|
||||
setTimeout(h, 1);
|
||||
return new Response("Aborted.");
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user