70 lines
1.9 KiB
JavaScript
70 lines
1.9 KiB
JavaScript
// frontend/js/api.js
|
|
// Base URL for backend API (adjust if using different host/port)
|
|
const API_BASE = "http://localhost:5000/api";
|
|
|
|
export async function fetchCases(params = {}) {
|
|
const query = new URLSearchParams(params).toString();
|
|
const res = await fetch(`${API_BASE}/cases${query ? `?${query}` : ''}`);
|
|
return await res.json();
|
|
}
|
|
|
|
export async function createCase(data) {
|
|
const res = await fetch(`${API_BASE}/cases`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(data),
|
|
});
|
|
return await res.json();
|
|
}
|
|
|
|
export async function getCase(id) {
|
|
const res = await fetch(`${API_BASE}/cases/${id}`);
|
|
return await res.json();
|
|
}
|
|
|
|
export async function updateCase(id, data) {
|
|
const res = await fetch(`${API_BASE}/cases/${id}`, {
|
|
method: "PUT",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(data),
|
|
});
|
|
return await res.json();
|
|
}
|
|
|
|
export async function deleteCase(id) {
|
|
const res = await fetch(`${API_BASE}/cases/${id}`, { method: "DELETE" });
|
|
return await res.json();
|
|
}
|
|
|
|
export async function uploadFiles(caseId, fileList) {
|
|
const form = new FormData();
|
|
for (const f of fileList) {
|
|
form.append("files", f);
|
|
}
|
|
const res = await fetch(`${API_BASE}/cases/${caseId}/files`, {
|
|
method: "POST",
|
|
body: form,
|
|
});
|
|
return await res.json();
|
|
}
|
|
|
|
export async function listFiles(caseId) {
|
|
const res = await fetch(`${API_BASE}/cases/${caseId}/files`);
|
|
return await res.json();
|
|
}
|
|
|
|
export async function getConfiguredPlatforms() {
|
|
const res = await fetch(`${API_BASE}/credentials`);
|
|
const data = await res.json();
|
|
return data.configured_platforms || [];
|
|
}
|
|
|
|
export async function saveCredentials(platform, data) {
|
|
const res = await fetch(`${API_BASE}/credentials/${platform}`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(data),
|
|
});
|
|
return await res.json();
|
|
}
|