Wire all dashboard buttons: auth downloads, get_log feedback, action tests.
This commit is contained in:
@@ -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 }),
|
||||
}),
|
||||
|
||||
20
server/web/src/api/download.ts
Normal file
20
server/web/src/api/download.ts
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user