2024-07-16 19:43:35 +00:00
|
|
|
import { DatagramSocket } from './websocket'
|
2024-08-03 16:52:33 +00:00
|
|
|
import { BatchTimer } from './batch-timer'
|
2024-06-29 17:04:08 +00:00
|
|
|
|
|
|
|
function _(key: string, value: any | null | undefined = undefined): any | null {
|
|
|
|
const x = <any>window;
|
|
|
|
if (value !== undefined) {
|
|
|
|
x[key] = value;
|
|
|
|
}
|
|
|
|
return x[key];
|
|
|
|
}
|
|
|
|
|
|
|
|
function $(id: string): HTMLElement | null {
|
|
|
|
return document.getElementById(id);
|
|
|
|
}
|
|
|
|
|
2024-07-16 19:43:35 +00:00
|
|
|
function errMsg(msg: string): void {
|
|
|
|
const div = $("err_div");
|
|
|
|
const w = $("err_wrapper");
|
|
|
|
if (div && w) {
|
|
|
|
div.innerText = msg;
|
|
|
|
w.style.display = "block";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function closeErr(): void {
|
|
|
|
const w = $("err_wrapper");
|
|
|
|
if (w) {
|
|
|
|
w.style.display = "none";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-01 03:51:25 +00:00
|
|
|
async function authorizedFetch(method: string, uri: string, body: any): Promise<Response> {
|
|
|
|
const headers = new Headers()
|
2024-07-16 19:43:35 +00:00
|
|
|
headers.set('Authorization', 'Bearer ' + DatagramSocket.skey)
|
2024-07-01 03:51:25 +00:00
|
|
|
return await fetch(uri, {
|
|
|
|
method: method,
|
|
|
|
headers: headers,
|
|
|
|
body: body,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-07-16 19:43:35 +00:00
|
|
|
export default { _, $, authorizedFetch, errMsg, closeErr }
|