mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 20:12:52 +08:00
fix(admin): correct TeamSpeak member counts and action feedback
This commit is contained in:
1 parent
88439181ae
commit
4bff2133b6
9 files changed
+196
-26
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { request as httpRequest } from "node:http";
|
||||
import { request as httpsRequest } from "node:https";
|
||||
import { WebQueryHttpError } from "@honeybbq/teamspeak/query";
|
||||
|
||||
/** Keep the SDK's WebQuery protocol, but bound HTTP requests to this admin operation.
|
||||
* Node's global fetch blocks WebQuery's default port 10080. */
|
||||
@@ -18,9 +19,20 @@ export function webQueryFetch(lifetime: AbortSignal): typeof fetch {
|
||||
chunks.push(chunk);
|
||||
});
|
||||
res.on("error", reject);
|
||||
res.on("end", () => resolve(new Response(Buffer.concat(chunks), {
|
||||
status: res.statusCode ?? 502, statusText: res.statusMessage ?? "",
|
||||
})));
|
||||
res.on("end", () => {
|
||||
const body = Buffer.concat(chunks), status = res.statusCode ?? 502;
|
||||
if (status < 200 || status >= 300) {
|
||||
// SDK beta.19 accepts status.code=0 even on HTTP failures. Keep genuine TS errors,
|
||||
// but never turn a proxy's failed HTTP response into a successful empty result.
|
||||
let tsError = false;
|
||||
try {
|
||||
const code: unknown = JSON.parse(body.toString("utf8"))?.status?.code;
|
||||
tsError = typeof code === "number" && Number.isSafeInteger(code) && code > 0;
|
||||
} catch { /* HTTP status is authoritative when no TS error is present. */ }
|
||||
if (!tsError) { reject(new WebQueryHttpError(status, res.statusMessage ?? "")); return; }
|
||||
}
|
||||
resolve(new Response(body, { status, statusText: res.statusMessage ?? "" }));
|
||||
});
|
||||
});
|
||||
req.on("error", reject);
|
||||
req.end(init.body as string);
|
||||
|
||||
Reference in new issue
Block a user