Archived
Добавлены frontend API управления и мониторинга
This commit is contained in:
+4
-18
@@ -1,33 +1,17 @@
|
||||
const BASE = "/api";
|
||||
const TOKEN_KEY = "access_token";
|
||||
|
||||
export function getToken() { return sessionStorage.getItem(TOKEN_KEY); }
|
||||
export function setToken(token) { sessionStorage.setItem(TOKEN_KEY, token); }
|
||||
export function clearToken() { sessionStorage.removeItem(TOKEN_KEY); }
|
||||
|
||||
async function request(path, options = {}) {
|
||||
const token = getToken();
|
||||
const response = await fetch(`${BASE}${path}`, {
|
||||
...options,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
||||
...(options.headers || {}),
|
||||
},
|
||||
});
|
||||
const response = await fetch(`${BASE}${path}`, { ...options, headers: { "Content-Type": "application/json", ...(token ? { Authorization: `Bearer ${token}` } : {}), ...(options.headers || {}) } });
|
||||
const data = await response.json().catch(() => ({}));
|
||||
if (!response.ok) throw new Error(data.detail || "Ошибка запроса");
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function register(email, password) { return request("/auth/register", { method: "POST", body: JSON.stringify({ email, password }) }); }
|
||||
export async function login(email, password) {
|
||||
const response = await fetch(`${BASE}/auth/login`, { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded" }, body: new URLSearchParams({ username: email, password }) });
|
||||
const data = await response.json().catch(() => ({}));
|
||||
if (!response.ok) throw new Error(data.detail || "Ошибка входа");
|
||||
setToken(data.access_token);
|
||||
return data;
|
||||
}
|
||||
export async function login(email, password) { const response = await fetch(`${BASE}/auth/login`, { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded" }, body: new URLSearchParams({ username: email, password }) }); const data = await response.json().catch(() => ({})); if (!response.ok) throw new Error(data.detail || "Ошибка входа"); setToken(data.access_token); return data; }
|
||||
export function getMe() { return request("/auth/me"); }
|
||||
export function listTemplates() { return request("/templates"); }
|
||||
export function listProxmoxTemplates() { return request("/templates/from-proxmox"); }
|
||||
@@ -36,3 +20,5 @@ export function deactivateTemplate(id) { return request(`/templates/${id}`, { me
|
||||
export function listInstances() { return request("/instances"); }
|
||||
export function createInstance(payload) { return request("/instances", { method: "POST", body: JSON.stringify(payload) }); }
|
||||
export function deleteInstance(id) { return request(`/instances/${id}`, { method: "DELETE" }); }
|
||||
export function instanceAction(id, action) { return request(`/instances/${id}/action`, { method: "POST", body: JSON.stringify({ action }) }); }
|
||||
export function getInstanceStats(id) { return request(`/instances/${id}/stats`); }
|
||||
|
||||
Reference in New Issue
Block a user