refator_comm1

This commit is contained in:
Mateusz Gruszczyński
2025-10-18 20:58:51 +02:00
parent 050d7d34df
commit 2682a0ff4f
11 changed files with 896 additions and 1035 deletions

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

@@ -0,0 +1,23 @@
// Każda funkcja = jedno zapytanie (łatwy prefetch i równoległość)
export const api = {
snapshot: (node) => fetch(`/api/info?node=${encodeURIComponent(node||'')}`).then(r=>r.json()),
// lżejsze mikro-endpointy:
clusterBrief: () => fetch('/api/cluster').then(r=>r.json()),
nodesSummary: () => fetch('/api/nodes/summary').then(r=>r.json()),
units: (node) => fetch(`/api/units?node=${encodeURIComponent(node||'')}`).then(r=>r.json()),
replicationAll: () => fetch('/api/replication/all').then(r=>r.json()),
vmDetail: (sid) => fetch('/api/vm?sid=' + encodeURIComponent(sid)).then(r=>r.json()),
nodeDetail: (name) => fetch('/api/node?name=' + encodeURIComponent(name)).then(r=>r.json()),
listNonHA: () => fetch('/api/list-vmct').then(r=>r.json()),
listAllVmct: () => fetch('/api/list-all-vmct').then(r=>r.json()),
action: (act, node) => fetch('/api/'+act, {method:'POST', headers:{'Content-Type':'application/json'}, body:JSON.stringify({node})}).then(r=>r.json()),
vmAction: (sid, action, target) => {
const body = { sid, action }; if (target) body.target = target;
return fetch('/api/vm-action', { method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify(body)}).then(r=>r.json());
},
taskStatus: (upid, node) => fetch(`/api/task-status?upid=${encodeURIComponent(upid)}&node=${encodeURIComponent(node)}`).then(r=>r.json()),
taskLog: (upid, node, start=0) => fetch(`/api/task-log?upid=${encodeURIComponent(upid)}&node=${encodeURIComponent(node)}&start=${start}`).then(r=>r.json())
};