This commit is contained in:
2026-03-27 03:58:57 +08:00
commit 86eba27a24
38 changed files with 4074 additions and 0 deletions

43
static/js/api.js Normal file
View File

@@ -0,0 +1,43 @@
/**
* static/js/api.js
* Thin fetch wrappers for all HTTP API endpoints.
*/
const BASE = '';
async function request(method, path, body) {
const opts = {
method,
headers: { 'Content-Type': 'application/json' },
};
if (body !== undefined) opts.body = JSON.stringify(body);
const res = await fetch(BASE + path, opts);
if (res.status === 204) return null;
const data = await res.json();
if (!res.ok) {
const msg = data?.detail || `HTTP ${res.status}`;
throw new Error(msg);
}
return data;
}
export const api = {
// Health
health: () => request('GET', '/healthz'),
// Status
status: () => request('GET', '/api/status'),
// Instructions
listInstructions: (status='all') => request('GET', `/api/instructions?status=${status}`),
createInstruction: (content) => request('POST', '/api/instructions', { content }),
updateInstruction: (id, content) => request('PATCH', `/api/instructions/${id}`, { content }),
deleteInstruction: (id) => request('DELETE', `/api/instructions/${id}`),
// Config
getConfig: () => request('GET', '/api/config'),
updateConfig: (patch) => request('PATCH', '/api/config', patch),
};