Spaces:
Sleeping
Sleeping
File size: 1,854 Bytes
1f6c75f e3531a1 ed439ff 1f6c75f 9aae0b0 1f6c75f | 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 68 69 70 71 72 | import axios from "axios";
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || "";
export const api = axios.create({
baseURL: API_BASE_URL,
});
export async function detectPlate(file) {
const formData = new FormData();
formData.append("file", file);
const response = await api.post("/api/detect", formData, {
headers: {
"Content-Type": "multipart/form-data",
},
});
return response.data;
}
export async function getVehicles() {
const response = await api.get("/api/vehicles");
return response.data;
}
export async function addVehicle(data, photoFile) {
const formData = new FormData();
formData.append("plat", data.plat);
formData.append("nama_pemilik", data.nama_pemilik);
formData.append("jenis_kendaraan", data.jenis_kendaraan || "-");
formData.append("keterangan", data.keterangan || "-");
if (photoFile) {
formData.append("foto", photoFile);
}
const response = await api.post("/api/vehicles", formData, {
headers: { "Content-Type": "multipart/form-data" },
});
return response.data;
}
export async function updateVehicle(plat, data) {
const response = await api.put(`/api/vehicles/${plat}`, data);
return response.data;
}
export async function deleteVehicle(plat) {
const response = await api.delete(`/api/vehicles/${plat}`);
return response.data;
}
export async function getHistory() {
const response = await api.get("/api/history");
return response.data;
}
export async function deleteHistoryRecord(index) {
const response = await api.delete(`/api/history/${index}`);
return response.data;
}
export async function clearAllHistory() {
const response = await api.delete("/api/history");
return response.data;
}
export function getMediaUrl(path) {
if (!path) return "";
if (path.startsWith("http")) return path;
return `${API_BASE_URL}${path}`;
}
|