remove all clients

This commit is contained in:
KingKDot
2026-03-28 22:18:33 -05:00
parent 67616e78f3
commit 5a40164962
4 changed files with 102 additions and 0 deletions
+5
View File
@@ -265,6 +265,11 @@ export function deleteClientRow(id: string) {
db.run(`DELETE FROM clients WHERE id=?`, id);
}
export function deleteOfflineClientRows(): number {
const result = db.run(`DELETE FROM clients WHERE online=0`);
return (result as any)?.changes || 0;
}
export function getClientOnlineState(id: string): boolean | null {
const row = db.query<{ online: number }>(`SELECT online FROM clients WHERE id=?`).get(id);
if (!row) return null;
@@ -6,6 +6,7 @@ import {
banIp,
clientExists,
deleteClientRow,
deleteOfflineClientRows,
getClientOnlineState,
getClientIp,
isIpBanned,
@@ -238,6 +239,33 @@ export async function handleClientRoutes(
return Response.json({ ok: true, updated: success }, { headers: deps.CORS_HEADERS });
}
if (req.method === "DELETE" && url.pathname === "/api/clients/offline") {
const user = await authenticateRequest(req);
if (!user) return new Response("Unauthorized", { status: 401 });
try {
requirePermission(user, "clients:control");
} catch (error) {
if (error instanceof Response) return error;
return new Response("Forbidden", { status: 403 });
}
const count = deleteOfflineClientRows();
notifyDashboardViewers();
const ip = server.requestIP(req)?.address || "unknown";
logAudit({
timestamp: Date.now(),
username: user.username,
ip,
action: AuditAction.COMMAND,
details: `wipe_offline_clients: removed ${count}`,
success: true,
});
return Response.json({ ok: true, count }, { headers: deps.CORS_HEADERS });
}
const clientDeleteMatch = url.pathname.match(/^\/api\/clients\/([^/]+)$/);
if (req.method === "DELETE" && clientDeleteMatch) {
const user = await authenticateRequest(req);