/
keorlov
/
collsim
Обзор
Документация
Войти
/
keorlov
/
collsim
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
frontend/src/api.js
75 строк
2 KB
Konstantin Orlov
wip
14 июл 2026, 12:34
14 июл 2026, 12:34
d40368b
Код
Авторство
О чём код?
const BASE = import.meta.env.VITE_API_BASE || ""; async function parseError(res) { let detail = ""; try { detail = JSON.stringify(await res.json()); } catch { try { detail = await res.text(); } catch { detail = res.statusText; } } return `HTTP ${res.status}: ${detail}`; } export async function simulate(params = {}) { const res = await fetch(`${BASE}/simulate`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(params), }); if (!res.ok) throw new Error(await parseError(res)); return res.json(); } export async function getSimulation(id) { const res = await fetch(`${BASE}/simulate/${id}`); if (!res.ok) throw new Error(await parseError(res)); return res.json(); } export async function listSimulations() { const res = await fetch(`${BASE}/simulations`); if (!res.ok) throw new Error(await parseError(res)); return res.json(); } export async function disposeSimulation(id) { const res = await fetch(`${BASE}/simulate/${id}`, { method: "DELETE" }); if (!res.ok) throw new Error(await parseError(res)); return res.json(); } export async function health() { const res = await fetch(`${BASE}/health`); if (!res.ok) throw new Error(await parseError(res)); return res.json(); } export async function getSimulationParams() { const res = await fetch(`${BASE}/simulation_params`); if (!res.ok) throw new Error(await parseError(res)); return res.json(); } export async function getSimulationResults(id) { const res = await fetch(`${BASE}/simulation_results/${id}`); if (!res.ok) throw new Error(await parseError(res)); return res.json(); } export async function getSimulationClients(id, strategy = "user", offset = 0, limit = 50) { const params = new URLSearchParams({ strategy, offset: String(offset), limit: String(limit) }); const res = await fetch(`${BASE}/simulation_clients/${id}?${params}`); if (!res.ok) throw new Error(await parseError(res)); return res.json(); } export async function getSimulationClientEvents(id, clientId, strategy = "user") { const params = new URLSearchParams({ strategy }); const res = await fetch(`${BASE}/simulation_client_events/${id}/${clientId}?${params}`); if (!res.ok) throw new Error(await parseError(res)); return res.json(); }