import { http } from "./client"; import { apiUrl } from "@/config/runtime"; import type { ApproversResponse, CompareRequest, DebugRequest, DebugResponse, DemoEntry, DemoText, DetectRequest, DetectResponse, DetectionLayersResponse, JobStatus, PdfLayoutResponse, PdfOverlayResponse, RenderRequest, RenderResponse, SystemStats, Timing, UiConfig, } from "./types"; // ---- Bootstrap ---- export async function getUiConfig(): Promise { return (await http.get("/api/system/ui-config")).data; } export async function getSystemStats(): Promise { return (await http.get("/api/system/stats")).data; } export async function getDetectionLayers(): Promise { return (await http.get("/api/detection/layers")).data; } export async function getApprovers(): Promise { return (await http.get("/api/approvers")).data; } export async function getDemoList(): Promise { return (await http.get("/api/demo/list")).data; } export async function getDemoText(key: string): Promise { return (await http.get(`/api/demo/${key}`)).data; } // ---- Detection / render ---- export async function detect(body: DetectRequest): Promise { return (await http.post("/api/detect", body)).data; } export async function render(body: RenderRequest): Promise { return (await http.post("/api/render", body)).data; } export async function detectDebug(body: DebugRequest): Promise { return (await http.post("/api/detect/debug", body)).data; } export async function getDetectTimings(docId: string): Promise { const res = await http.get<{ doc_id: string; timings: Timing[] }>( `/api/detect/timings/${docId}`, ); return res.data.timings; } // ---- Job (avvio) ---- export async function startDetect(body: DetectRequest): Promise { return (await http.post("/api/detect/start", body)).data; } export async function startCompare(body: CompareRequest): Promise { return (await http.post("/api/detect/compare/start", body)).data; } export async function startDebug(body: DebugRequest): Promise { return (await http.post("/api/detect/debug/start", body)).data; } export async function getJob(jobId: string): Promise { return (await http.get(`/api/job/${jobId}`)).data; } // ---- PDF ---- export async function uploadPdf(form: FormData): Promise { const res = await http.post("/api/pdf/upload", form, { headers: { "Content-Type": "multipart/form-data" }, }); return res.data; } export async function getPdfJob(jobId: string): Promise { return (await http.get(`/api/pdf/job/${jobId}`)).data; } export async function getPdfLayout(docId: string): Promise { return (await http.get(`/api/pdf/layout/${docId}`)).data; } export async function getPdfOverlay( docId: string, params: Record, ): Promise { const res = await http.get(`/api/pdf/overlay/${docId}`, { params, }); return res.data; } /** URL assoluto al PDF originale (per pdf.js getDocument). */ export function pdfRawUrl(docId: string): string { return apiUrl(`/api/pdf/raw/${docId}`); } /** URL assoluto al download del PDF redatto/offuscato (apre il file). */ export function pdfDownloadUrl(docId: string, query: string): string { const base = `/api/pdf/download/${docId}/redact`; return apiUrl(query ? `${base}?${query}` : base); }