remove old bs code, start getting ready for freebsd and openbsd support
This commit is contained in:
@@ -122,32 +122,6 @@ export async function sendCommand(clientId, action) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function sendSupportChat(clientId, message, requireReply = true) {
|
||||
try {
|
||||
const res = await fetch(`/api/clients/${clientId}/command`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ action: "support_chat", message, requireReply }),
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
return {
|
||||
ok: false,
|
||||
error: data?.error || `support chat failed ${res.status}`,
|
||||
response: "",
|
||||
};
|
||||
}
|
||||
return {
|
||||
ok: Boolean(data?.ok),
|
||||
error: data?.error || "",
|
||||
response: typeof data?.response === "string" ? data.response : "",
|
||||
};
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
return { ok: false, error: "Support chat request failed", response: "" };
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchVoiceCapabilities(clientId) {
|
||||
try {
|
||||
const res = await fetch(`/api/clients/${clientId}/command`, {
|
||||
|
||||
@@ -71,7 +71,6 @@ export type CommandType =
|
||||
| "file_chmod"
|
||||
| "file_execute"
|
||||
| "silent_exec"
|
||||
| "support_chat"
|
||||
| "voice_session_start"
|
||||
| "voice_session_stop"
|
||||
| "voice_downlink"
|
||||
|
||||
@@ -385,56 +385,6 @@ export async function handleClientRoutes(
|
||||
} catch (error: any) {
|
||||
return Response.json({ ok: false, error: error.message }, { status: 500 });
|
||||
}
|
||||
} else if (action === "support_chat") {
|
||||
const message = typeof body?.message === "string" ? body.message.trim() : "";
|
||||
const requireReply = body?.requireReply !== false;
|
||||
const operator = typeof user?.username === "string" ? user.username.trim() : "";
|
||||
|
||||
if (!message) {
|
||||
return Response.json({ ok: false, error: "Message is required" }, { status: 400 });
|
||||
}
|
||||
if (message.length > 1200) {
|
||||
return Response.json({ ok: false, error: "Message too long (max 1200 characters)" }, { status: 400 });
|
||||
}
|
||||
|
||||
const cmdId = uuidv4();
|
||||
const waitTimeoutMs = 4 * 60 * 1000;
|
||||
let replyPromise: Promise<{ ok: boolean; message?: string }> | null = null;
|
||||
|
||||
if (requireReply) {
|
||||
replyPromise = new Promise((resolve, reject) => {
|
||||
const timeout = setTimeout(() => {
|
||||
deps.pendingCommandReplies.delete(cmdId);
|
||||
reject(new Error("Support chat reply timed out"));
|
||||
}, waitTimeoutMs);
|
||||
deps.pendingCommandReplies.set(cmdId, { resolve, reject, timeout });
|
||||
});
|
||||
}
|
||||
|
||||
target.ws.send(
|
||||
encodeMessage({
|
||||
type: "command",
|
||||
commandType: "support_chat",
|
||||
id: cmdId,
|
||||
payload: {
|
||||
message,
|
||||
requireReply,
|
||||
operator,
|
||||
},
|
||||
}),
|
||||
);
|
||||
metrics.recordCommand("support_chat");
|
||||
|
||||
if (!replyPromise) {
|
||||
return Response.json({ ok: true });
|
||||
}
|
||||
|
||||
try {
|
||||
const reply = await replyPromise;
|
||||
return Response.json({ ok: reply.ok, response: reply.message || "" }, { headers: deps.CORS_HEADERS });
|
||||
} catch (error: any) {
|
||||
return Response.json({ ok: false, error: error.message || "Support chat failed" }, { status: 504 });
|
||||
}
|
||||
} else if (action === "voice_capabilities") {
|
||||
const cmdId = uuidv4();
|
||||
const replyPromise: Promise<{ ok: boolean; message?: string }> = new Promise((resolve, reject) => {
|
||||
|
||||
Reference in New Issue
Block a user