Wire all dashboard buttons: auth downloads, get_log feedback, action tests.

This commit is contained in:
drjones
2026-05-28 19:56:11 -07:00
parent 9e26c4babb
commit fda72041f0
8 changed files with 143 additions and 8 deletions

View File

@@ -92,9 +92,9 @@ export const api = {
sendAgentCommand: (
id: string,
action: string,
payload?: { tail_lines?: number; command?: string; path?: string; data?: string }
payload?: Record<string, unknown>
) =>
fetchJSON<{ success: boolean }>(`/agents/${id}/command`, {
fetchJSON<{ success: boolean; error?: string }>(`/agents/${id}/command`, {
method: 'POST',
body: JSON.stringify({ action, ...payload }),
}),

View File

@@ -0,0 +1,20 @@
import { authHeaders } from './auth';
/** Download a protected /api/v1 file using session auth (build uninstall scripts, etc.). */
export async function downloadAuthedFile(apiPath: string, filename: string): Promise<void> {
const path = apiPath.startsWith('/api/v1') ? apiPath : `/api/v1${apiPath.startsWith('/') ? apiPath : `/${apiPath}`}`;
const res = await fetch(path, { headers: authHeaders() });
if (!res.ok) {
const err = await res.text();
throw new Error(err || `Download failed (${res.status})`);
}
const blob = await res.blob();
const objectUrl = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = objectUrl;
a.download = filename;
document.body.appendChild(a);
a.click();
a.remove();
URL.revokeObjectURL(objectUrl);
}