Spaces:
Sleeping
Sleeping
File size: 2,361 Bytes
5fdeef5 f09c2db 5fdeef5 f09c2db 5fdeef5 f184c04 5fdeef5 f09c2db f184c04 5fdeef5 f09c2db 0fd3a61 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | import axios from "axios";
const baseURL = import.meta.env.VITE_API_URL || "http://localhost:8000/api";
export const api = axios.create({ baseURL });
export const uploadImage = (file, location) => {
const form = new FormData();
form.append("file", file);
if (location) form.append("location", location);
return api.post("/upload", form).then((r) => r.data);
};
export const uploadVideo = (file, location) => {
const form = new FormData();
form.append("file", file);
if (location) form.append("location", location);
return api.post("/video-upload", form).then((r) => r.data);
};
export const getViolations = (params) =>
api.get("/violations", { params }).then((r) => r.data);
export const updateViolationStatus = (id, status) =>
api.patch(`/violations/${id}`, { status }).then((r) => r.data);
export const getViolationEvidence = (id) =>
api.get(`/violations/${id}/evidence`).then((r) => r.data);
export const getSummary = () =>
api.get("/analytics/summary").then((r) => r.data);
export const getByType = () =>
api.get("/analytics/by-type").then((r) => r.data);
export const getRules = () =>
api.get("/rules").then((r) => r.data);
export const getTrends = () =>
api.get("/analytics/trends").then((r) => r.data);
export const getTopPlates = () =>
api.get("/analytics/top-plates").then((r) => r.data);
export const API_ORIGIN = baseURL.replace(/\/api\/?$/, "");
// Build a servable evidence URL from a stored annotated-image path (any OS separator).
export const evidenceUrl = (path) =>
path ? `${API_ORIGIN}/evidence/${String(path).split(/[\\/]/).pop()}` : null;
export const getHealth = () =>
axios.get(`${API_ORIGIN}/health`).then((r) => r.data);
// ββ Challan evidence store (MongoDB) ββββββββββββββββββββββββββββββββββββββ
export const getChallanTree = () =>
api.get("/challans").then((r) => r.data);
export const getChallanList = (params) =>
api.get("/challans/list", { params }).then((r) => r.data);
export const issueChallan = (id) =>
api.patch(`/challans/${id}/issue`).then((r) => r.data);
// Challan crops are served from the backend's /challans static mount; the API
// returns an evidence_url like "/challans/two_wheeler/HELMET/uuid.jpg".
export const challanUrl = (url) => (url ? `${API_ORIGIN}${url}` : null);
|