Commit 356bf7b4 authored by Administrator's avatar Administrator

Update frontend/src/api.js via Son of Anton

parent fedb1847
......@@ -21,34 +21,9 @@ async function request(method, path, token, body) {
return res.json();
}
// ═══════════════════════════════════════
// Utility: Extract fenced code blocks from markdown
// ═══════════════════════════════════════
export function extractCodeBlocks(markdown) {
if (!markdown) return [];
const blocks = [];
const re = /```([\w.:-]*)[ \t]*\r?\n([\s\S]*?)```/g;
let match;
while ((match = re.exec(markdown)) !== null) {
const raw = match[1] || "";
let lang = raw, filename = null;
const colonIdx = raw.indexOf(":");
if (colonIdx !== -1) {
lang = raw.slice(0, colonIdx);
filename = raw.slice(colonIdx + 1) || null;
}
blocks.push({ language: lang.toLowerCase(), filename, code: match[2] });
}
return blocks;
}
// ═══════════════════════════════════════
// ═══════════════════════════════════════════
// Auth
// ═══════════════════════════════════════
export const getRegistrationStatus = () => request("GET", "/auth/registration-status", null);
// ═══════════════════════════════════════════
export const login = (username, password) =>
request("POST", "/auth/login", null, { username, password });
......@@ -58,9 +33,11 @@ export const register = (username, email, password) =>
export const getMe = (token) => request("GET", "/auth/me", token);
// ═══════════════════════════════════════
export const getRegistrationStatus = () => request("GET", "/auth/registration-status", null);
// ═══════════════════════════════════════════
// Chats
// ═══════════════════════════════════════
// ═══════════════════════════════════════════
export const listChats = (token) => request("GET", "/chats", token);
......@@ -78,6 +55,9 @@ export const deleteChat = (token, chatId) =>
export const getMessages = (token, chatId) =>
request("GET", `/chats/${chatId}/messages`, token);
export const checkGenerating = (token, chatId) =>
request("GET", `/chats/${chatId}/generating`, token);
export async function* streamMessage(token, chatId, body, signal) {
const res = await fetch(`${BASE}/chats/${chatId}/messages`, {
method: "POST", headers: headers(token),
......@@ -108,19 +88,9 @@ export async function* streamMessage(token, chatId, body, signal) {
}
}
export const checkGenerating = (token, chatId) =>
request("GET", `/chats/${chatId}/generating`, token);
export async function commitFromChat(token, chatId, data) {
return request("POST", `/chats/${chatId}/commit`, token, data);
}
export const refreshRepoContext = (token, chatId) =>
request("POST", `/chats/${chatId}/refresh-repo`, token);
// ═══════════════════════════════════════
// ═══════════════════════════════════════════
// Attachments
// ═══════════════════════════════════════
// ═══════════════════════════════════════════
export async function uploadAttachments(token, chatId, files) {
const form = new FormData();
......@@ -142,9 +112,9 @@ export function getAttachmentUrl(attachmentId) {
export const deleteAttachment = (token, attachmentId) =>
request("DELETE", `/attachments/${attachmentId}`, token);
// ═══════════════════════════════════════
// Knowledge Base
// ═══════════════════════════════════════
// ═══════════════════════════════════════════
// Knowledge Bases
// ═══════════════════════════════════════════
export const listKnowledgeBases = (token) => request("GET", "/knowledge", token);
......@@ -157,12 +127,6 @@ export const getKnowledgeBase = (token, kbId) =>
export const deleteKnowledgeBase = (token, kbId) =>
request("DELETE", `/knowledge/${kbId}`, token);
export const updateKnowledgeBase = (token, kbId, data) =>
request("PUT", `/knowledge/${kbId}`, token, data);
export const deleteKnowledgeDocument = (token, kbId, docId) =>
request("DELETE", `/knowledge/${kbId}/documents/${docId}`, token);
export async function uploadDocuments(token, kbId, files) {
const form = new FormData();
for (const file of files) form.append("files", file);
......@@ -179,9 +143,84 @@ export async function uploadDocuments(token, kbId, files) {
export const uploadDocument = (token, kbId, file) =>
uploadDocuments(token, kbId, [file]);
// ═══════════════════════════════════════
// ═══════════════════════════════════════════
// GitLab — User-facing (for chat integration)
// ═══════════════════════════════════════════
export const listLinkedRepos = (token) =>
request("GET", "/chats/available-repos", token);
export const getRepoBranches = (token, repoId) =>
request("GET", `/chats/repos/${repoId}/branches`, token);
export const commitFromChat = (token, chatId, data) =>
request("POST", `/chats/${chatId}/commit`, token, data);
export const refreshRepoContext = (token, chatId) =>
request("POST", `/chats/${chatId}/refresh-repo`, token);
// ═══════════════════════════════════════════
// GitLab — Admin (for GitLab Command Center)
// ═══════════════════════════════════════════
export const getGitlabSettings = (token) => request("GET", "/gitlab/settings", token);
export const updateGitlabSettings = (token, data) => request("PUT", "/gitlab/settings", token, data);
export const testGitlabConnection = (token) => request("POST", "/gitlab/test-connection", token);
export const searchGitlabProjects = (token, search, owned) =>
request("GET", `/gitlab/projects?search=${encodeURIComponent(search || "")}&owned=${owned || false}`, token);
export const createGitlabProject = (token, data) => request("POST", "/gitlab/projects", token, data);
export const adminListRepos = (token) => request("GET", "/gitlab/repos", token);
export const linkRepo = (token, gitlabProjectId) => request("POST", "/gitlab/repos", token, { gitlab_project_id: gitlabProjectId });
export const unlinkRepo = (token, repoId) => request("DELETE", `/gitlab/repos/${repoId}`, token);
export const analyzeRepo = (token, repoId) => request("POST", `/gitlab/repos/${repoId}/analyze`, token);
export const getRepoMap = (token, repoId) => request("GET", `/gitlab/repos/${repoId}/map`, token);
export const getRepoTree = (token, repoId, path, ref) =>
request("GET", `/gitlab/repos/${repoId}/tree?path=${encodeURIComponent(path || "")}&ref=${encodeURIComponent(ref || "")}`, token);
export const getRepoFile = (token, repoId, path, ref) =>
request("GET", `/gitlab/repos/${repoId}/file?path=${encodeURIComponent(path)}&ref=${encodeURIComponent(ref || "")}`, token);
export const adminGetBranches = (token, repoId) => request("GET", `/gitlab/repos/${repoId}/branches`, token);
export const adminCommitFiles = (token, repoId, data) => request("POST", `/gitlab/repos/${repoId}/commit`, token, data);
export const adminCommitSingle = (token, repoId, data) => request("POST", `/gitlab/repos/${repoId}/commit-single`, token, data);
export const createBranch = (token, repoId, data) => request("POST", `/gitlab/repos/${repoId}/branches`, token, data);
export const createMergeRequest = (token, repoId, data) => request("POST", `/gitlab/repos/${repoId}/merge-request`, token, data);
export const listActions = (token, status) => request("GET", `/gitlab/actions?status=${status || "pending"}`, token);
export const createAction = (token, data) => request("POST", "/gitlab/actions", token, data);
export const approveAction = (token, actionId) => request("POST", `/gitlab/actions/${actionId}/approve`, token);
export const rejectAction = (token, actionId) => request("POST", `/gitlab/actions/${actionId}/reject`, token);
// ═══════════════════════════════════════════
// Export (PPTX / DOCX)
// ═══════════════════════════════════════════
export async function exportPptx(token, markdown, title) {
const res = await fetch(`${BASE}/export/pptx`, {
method: "POST", headers: headers(token),
body: JSON.stringify({ markdown, title }),
});
if (!res.ok) throw new Error("Export failed");
const blob = await res.blob();
const url = URL.createObjectURL(blob);
const a = document.createElement("a"); a.href = url;
a.download = `${(title || "presentation").replace(/[^\w\s-]/g, "").trim().replace(/\s+/g, "-").slice(0, 60) || "presentation"}.pptx`;
a.click(); URL.revokeObjectURL(url);
}
export async function exportDocx(token, markdown, title) {
const res = await fetch(`${BASE}/export/docx`, {
method: "POST", headers: headers(token),
body: JSON.stringify({ markdown, title }),
});
if (!res.ok) throw new Error("Export failed");
const blob = await res.blob();
const url = URL.createObjectURL(blob);
const a = document.createElement("a"); a.href = url;
a.download = `${(title || "document").replace(/[^\w\s-]/g, "").trim().replace(/\s+/g, "-").slice(0, 60) || "document"}.docx`;
a.click(); URL.revokeObjectURL(url);
}
// ═══════════════════════════════════════════
// Admin
// ═══════════════════════════════════════
// ═══════════════════════════════════════════
export const adminStats = (token) => request("GET", "/admin/stats", token);
export const adminListUsers = (token) => request("GET", "/admin/users", token);
......@@ -189,20 +228,18 @@ export const adminCreateUser = (token, data) => request("POST", "/admin/users",
export const adminUpdateUser = (token, userId, data) => request("PUT", `/admin/users/${userId}`, token, data);
export const adminDeleteUser = (token, userId) => request("DELETE", `/admin/users/${userId}`, token);
export const adminListChats = (token) => request("GET", "/admin/chats", token);
export const adminGetAppSettings = (token) => request("GET", "/admin/app-settings", token);
export const adminUpdateAppSettings = (token, data) => request("PUT", "/admin/app-settings", token, data);
export const adminGetModels = (token) => request("GET", "/admin/models", token);
export const adminGetPermDefaults = (token) => request("GET", "/admin/permissions/defaults", token);
export const adminUpdatePermDefaults = (token, data) => request("PUT", "/admin/permissions/defaults", token, data);
export const adminApplyPermDefaults = (token) => request("POST", "/admin/permissions/apply-defaults", token);
export const adminGetUserPerms = (token, userId) => request("GET", `/admin/users/${userId}/permissions`, token);
export const adminUpdateUserPerms = (token, userId, data) => request("PUT", `/admin/users/${userId}/permissions`, token, data);
export const adminGetPermissionDefaults = (token) => request("GET", "/admin/permissions/defaults", token);
export const adminUpdatePermissionDefaults = (token, data) => request("PUT", "/admin/permissions/defaults", token, data);
export const adminApplyDefaults = (token) => request("POST", "/admin/permissions/apply-defaults", token);
export const adminGetUserPermissions = (token, userId) => request("GET", `/admin/users/${userId}/permissions`, token);
export const adminUpdateUserPermissions = (token, userId, data) => request("PUT", `/admin/users/${userId}/permissions`, token, data);
export const adminListModels = (token) => request("GET", "/admin/models", token);
// ═══════════════════════════════════════
// Files / Export
// ═══════════════════════════════════════
// ═══════════════════════════════════════════
// Files / Code Download
// ═══════════════════════════════════════════
export async function downloadZip(token, markdown, title) {
const res = await fetch(`${BASE}/files/download-zip`, {
......@@ -223,60 +260,4 @@ export async function downloadZip(token, markdown, title) {
const data = await res.json();
if (data.error) throw new Error(data.error);
}
}
export async function exportPptx(token, markdown, title) {
const res = await fetch(`${BASE}/export/pptx`, {
method: "POST", headers: headers(token),
body: JSON.stringify({ markdown, title }),
});
if (!res.ok) throw new Error("Export failed");
const blob = await res.blob();
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = (title || "presentation") + ".pptx";
a.click();
URL.revokeObjectURL(url);
}
export async function exportDocx(token, markdown, title) {
const res = await fetch(`${BASE}/export/docx`, {
method: "POST", headers: headers(token),
body: JSON.stringify({ markdown, title }),
});
if (!res.ok) throw new Error("Export failed");
const blob = await res.blob();
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = (title || "document") + ".docx";
a.click();
URL.revokeObjectURL(url);
}
// ═══════════════════════════════════════
// GitLab
// ═══════════════════════════════════════
export const gitlabGetSettings = (token) => request("GET", "/gitlab/settings", token);
export const gitlabUpdateSettings = (token, data) => request("PUT", "/gitlab/settings", token, data);
export const gitlabTestConnection = (token) => request("POST", "/gitlab/test-connection", token);
export const gitlabSearchProjects = (token, search, owned) => request("GET", `/gitlab/projects?search=${encodeURIComponent(search || "")}&owned=${owned || false}`, token);
export const gitlabCreateProject = (token, data) => request("POST", "/gitlab/projects", token, data);
export const gitlabListRepos = (token) => request("GET", "/gitlab/repos", token);
export const gitlabLinkRepo = (token, projectId) => request("POST", "/gitlab/repos", token, { gitlab_project_id: projectId });
export const gitlabUnlinkRepo = (token, repoId) => request("DELETE", `/gitlab/repos/${repoId}`, token);
export const gitlabGetTree = (token, repoId, path, ref) => request("GET", `/gitlab/repos/${repoId}/tree?path=${encodeURIComponent(path || "")}&ref=${encodeURIComponent(ref || "")}`, token);
export const gitlabGetFile = (token, repoId, path, ref) => request("GET", `/gitlab/repos/${repoId}/file?path=${encodeURIComponent(path)}&ref=${encodeURIComponent(ref || "")}`, token);
export const gitlabGetBranches = (token, repoId) => request("GET", `/gitlab/repos/${repoId}/branches`, token);
export const gitlabCommit = (token, repoId, data) => request("POST", `/gitlab/repos/${repoId}/commit`, token, data);
export const gitlabCommitSingle = (token, repoId, data) => request("POST", `/gitlab/repos/${repoId}/commit-single`, token, data);
export const gitlabCreateBranch = (token, repoId, data) => request("POST", `/gitlab/repos/${repoId}/branches`, token, data);
export const gitlabCreateMR = (token, repoId, data) => request("POST", `/gitlab/repos/${repoId}/merge-request`, token, data);
export const gitlabAnalyzeRepo = (token, repoId) => request("POST", `/gitlab/repos/${repoId}/analyze`, token);
export const gitlabGetRepoMap = (token, repoId) => request("GET", `/gitlab/repos/${repoId}/map`, token);
export const gitlabListActions = (token, status) => request("GET", `/gitlab/actions?status=${status || "pending"}`, token);
export const gitlabCreateAction = (token, data) => request("POST", "/gitlab/actions", token, data);
export const gitlabApproveAction = (token, actionId) => request("POST", `/gitlab/actions/${actionId}/approve`, token);
export const gitlabRejectAction = (token, actionId) => request("POST", `/gitlab/actions/${actionId}/reject`, token);
\ No newline at end of file
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment