mirror of
https://github.com/lifegpc/eh-downloader.git
synced 2026-07-08 01:31:00 +08:00
Update
This commit is contained in:
25
server/cfg.ts
Normal file
25
server/cfg.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { signal } from "@preact/signals";
|
||||
import { ConfigType } from "../config.ts";
|
||||
import { get_ws_host } from "./utils.ts";
|
||||
import { ConfigClientSocketData, ConfigSeverSocketData } from "./config.ts";
|
||||
|
||||
export const cfg = signal<ConfigType | undefined>(undefined);
|
||||
|
||||
export function initCfg() {
|
||||
const ws = new WebSocket(`${get_ws_host()}/api/config?current=1&type=ws`);
|
||||
console.log(ws);
|
||||
function sendMessage(mes: ConfigClientSocketData) {
|
||||
ws.send(JSON.stringify(mes));
|
||||
}
|
||||
ws.onmessage = (e) => {
|
||||
const d: ConfigSeverSocketData = JSON.parse(e.data);
|
||||
if (d.type === "close") {
|
||||
ws.close();
|
||||
} else if (d.type === "cfg") {
|
||||
cfg.value = d.cfg;
|
||||
}
|
||||
};
|
||||
self.addEventListener("beforeunload", () => {
|
||||
sendMessage({ type: "close" });
|
||||
});
|
||||
}
|
||||
7
server/config.ts
Normal file
7
server/config.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { ConfigType } from "../config.ts";
|
||||
|
||||
export type ConfigClientSocketData = { type: "close" };
|
||||
export type ConfigSeverSocketData = { type: "close" } | {
|
||||
type: "cfg";
|
||||
cfg: ConfigType;
|
||||
};
|
||||
Reference in New Issue
Block a user