snapix/frontend/src/service.js
2025-06-10 03:15:14 +03:00

34 lines
1.1 KiB
JavaScript

const API_BASE = "http://localhost:8000";
export async function getNamespaces() {
const res = await fetch(`${API_BASE}/namespaces`);
if (!res.ok) throw new Error("Failed to fetch namespaces");
return await res.json();
}
export async function getPVCs(namespace) {
const res = await fetch(`${API_BASE}/pvcs/${namespace}`);
if (!res.ok) throw new Error("Failed to fetch PVCs");
return await res.json();
}
export async function createBackup({ namespace, pvcName, backupName }) {
const res = await fetch(`${API_BASE}/backup`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ namespace, pvc_name: pvcName, backup_name: backupName }),
});
if (!res.ok) throw new Error("Failed to create backup");
return await res.json();
}
export async function restoreBackup({ namespace, targetPVC, backupName }) {
const res = await fetch(`${API_BASE}/restore`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ namespace, target_pvc: targetPVC, backup_name: backupName }),
});
if (!res.ok) throw new Error("Failed to restore backup");
return await res.json();
}