civilscan-frontend / src /api /client.js
Amir Aziz
Initial frontend deployment
f7725ca
Raw
History Blame Contribute Delete
1.51 kB
import axios from 'axios'
const BASE_URL = import.meta.env.VITE_API_URL || 'http://localhost:7860'
const api = axios.create({ baseURL: BASE_URL, timeout: 600000 })
api.interceptors.response.use(
(res) => res,
(err) => {
const message = err.response?.data?.detail || err.message || 'Error desconocido'
return Promise.reject(new Error(message))
}
)
export const uploadFile = (file, onProgress) => {
const formData = new FormData()
formData.append('file', file)
return api.post('/upload', formData, {
headers: { 'Content-Type': 'multipart/form-data' },
onUploadProgress: (e) => {
if (e.total && onProgress) onProgress(Math.round((e.loaded * 100) / e.total))
},
})
}
export const extractVideoFrames = (videoId) =>
api.post(`/extract-video-frames?video_id=${videoId}`)
export const runDetection = (imageIds, modelName, assetType, confThreshold = 0.45, engineerNotes = '') =>
api.post('/detect', {
image_ids: imageIds,
model_name: modelName,
asset_type: assetType,
conf_threshold: confThreshold,
engineer_notes: engineerNotes,
})
export const generateReport = (inspectionId, engineerNotes) =>
api.post('/generate-report', { inspection_id: inspectionId, engineer_notes: engineerNotes })
export const getModels = () => api.get('/models')
export const getInspections = () => api.get('/inspections')
export const getInspection = (id) => api.get(`/inspection/${id}`)
export const getDownloadUrl = (path) => `${BASE_URL}${path}`
export default api