/
ncit
/
c4panelmodel
Обзор
Документация
Войти
/
ncit
/
c4panelmodel
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
src/lib/api.ts
66 строк
3 KB
ncit
feat: implement full IcePanel feature clone (Phases 1-8)
09 июн 2026, 11:13
09 июн 2026, 11:13
858c15a
Код
Авторство
О чём код?
// Thin client-side fetch helpers for the editor. function getCsrfToken(): string | undefined { const match = document.cookie.match(/c4panel_csrf=([^;]+)/); return match?.[1]; } async function req(method: string, url: string, body?: unknown) { const headers: Record<string, string> = {}; if (body) headers['content-type'] = 'application/json'; const csrf = getCsrfToken(); if (csrf) headers['x-csrf-token'] = csrf; const res = await fetch(url, { method, headers, body: body ? JSON.stringify(body) : undefined }); if (!res.ok) { let msg = `${res.status}`; try { const data = await res.json(); msg = data.error ?? data.message ?? msg; } catch { /* ignore */ } throw new Error(msg); } return res.json(); } export const api = { createObject: (projectId: string, data: Record<string, unknown>) => req('POST', `/api/projects/${projectId}/objects`, data), updateObject: (projectId: string, objectId: string, data: Record<string, unknown>) => req('PATCH', `/api/projects/${projectId}/objects/${objectId}`, data), deleteObject: (projectId: string, objectId: string) => req('DELETE', `/api/projects/${projectId}/objects/${objectId}`), createConnection: (projectId: string, data: Record<string, unknown>) => req('POST', `/api/projects/${projectId}/connections`, data), updateConnection: (projectId: string, connectionId: string, data: Record<string, unknown>) => req('PATCH', `/api/projects/${projectId}/connections/${connectionId}`, data), deleteConnection: (projectId: string, connectionId: string) => req('DELETE', `/api/projects/${projectId}/connections/${connectionId}`), savePositions: (diagramId: string, data: Record<string, unknown>) => req('POST', `/api/diagrams/${diagramId}/positions`, data), addNodeToDiagram: (diagramId: string, data: { objectId: string; x: number; y: number }) => req('POST', `/api/diagrams/${diagramId}/nodes`, data), drilldown: (objectId: string) => req('POST', `/api/objects/${objectId}/drilldown`), // Tags listTags: (projectId: string) => req('GET', `/api/projects/${projectId}/tags`), tagAction: (projectId: string, data: Record<string, unknown>) => req('POST', `/api/projects/${projectId}/tags`, data), // Flows listFlows: (projectId: string) => req('GET', `/api/projects/${projectId}/flows`), flowAction: (projectId: string, data: Record<string, unknown>) => req('POST', `/api/projects/${projectId}/flows`, data), stepAction: (projectId: string, flowId: string, data: Record<string, unknown>) => req('POST', `/api/projects/${projectId}/flows/${flowId}/steps`, data), // Versions versionAction: (projectId: string, data: Record<string, unknown>) => req('POST', `/api/projects/${projectId}/versions`, data), // Connection tags connectionTagAction: (projectId: string, connectionId: string, data: Record<string, unknown>) => req('POST', `/api/projects/${projectId}/connections/${connectionId}/tags`, data) };