Files
WebSpeak-client-for-TeamSpeak/src/admin/webquery-fetch.ts
T
illusia 0af3236c30 feat: add GitHub skin store and organize instance administration
Adopt the pinned published TeamSpeak SDK and direct relay routing.
Add optional TeamSpeak Query administration with encrypted credentials
and separate WebSpeak access, site, operations and skin management.
Distribute Discord Voice through the GitHub skin index, preserve skin
state during updates, and correct KAAK scaling and screen fullscreen.

Validation: 831 tests; backend and frontend builds; five-language UI
checks from narrow screens through 4K and local Query fixture actions.
2026-10-24 12:52:59 +08:00

29 lines
1.2 KiB
TypeScript

import { request as httpRequest } from "node:http";
import { request as httpsRequest } from "node:https";
/** Keep the SDK's WebQuery protocol, but bound HTTP requests to this admin operation.
* Node's global fetch blocks WebQuery's default port 10080. */
export function webQueryFetch(lifetime: AbortSignal): typeof fetch {
return ((url: string, init: RequestInit) => new Promise<Response>((resolve, reject) => {
const request = new URL(url).protocol === "https:" ? httpsRequest : httpRequest;
const req = request(url, {
method: init.method, headers: init.headers as Record<string, string>,
signal: AbortSignal.any([lifetime, AbortSignal.timeout(8_000)]),
}, res => {
const chunks: Buffer[] = [];
let size = 0;
res.on("data", (chunk: Buffer) => {
size += chunk.length;
if (size > 8 * 1024 * 1024) { res.destroy(new Error("WebQuery response too large")); return; }
chunks.push(chunk);
});
res.on("error", reject);
res.on("end", () => resolve(new Response(Buffer.concat(chunks), {
status: res.statusCode ?? 502, statusText: res.statusMessage ?? "",
})));
});
req.on("error", reject);
req.end(init.body as string);
})) as typeof fetch;
}