mirror of
https://github.com/lifegpc/eh-downloader.git
synced 2026-07-08 01:31:00 +08:00
Update settings page
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import { Handlers } from "$fresh/server.ts";
|
||||
import { load_settings } from "../../config.ts";
|
||||
import { get_cfg_path } from "../../server.ts";
|
||||
import { ConfigType, load_settings, save_settings } from "../../config.ts";
|
||||
import { get_cfg_path, get_task_manager } from "../../server.ts";
|
||||
|
||||
const UNSAFE_TYPE: (keyof ConfigType)[] = ["base", "db_path"];
|
||||
const UNSAFE_TYPE2 = UNSAFE_TYPE as string[];
|
||||
|
||||
export const handler: Handlers = {
|
||||
async GET(_req, _ctx) {
|
||||
@@ -10,4 +13,29 @@ export const handler: Handlers = {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
},
|
||||
async POST(req, _ctx) {
|
||||
const content_type = req.headers.get("Content-Type");
|
||||
if (content_type === "application/json") {
|
||||
const d = await req.json();
|
||||
const path = get_cfg_path();
|
||||
const m = get_task_manager();
|
||||
let is_unsafe = false;
|
||||
const cfg = await load_settings(path);
|
||||
Object.getOwnPropertyNames(d).forEach((k) => {
|
||||
if (UNSAFE_TYPE2.indexOf(k) === -1) {
|
||||
cfg._data[k] = d[k];
|
||||
m.cfg._data[k] = d[k];
|
||||
} else {
|
||||
cfg._data[k] = d[k];
|
||||
is_unsafe = true;
|
||||
}
|
||||
});
|
||||
await save_settings(path, cfg, m.force_aborts);
|
||||
return new Response(JSON.stringify({ is_unsafe }), {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
} else {
|
||||
return new Response("Bad Request", { status: 400 });
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user