import axios from 'axios'; // Base URL for the API (proxied through Vite dev server) // Vite will proxy /api requests to the configured backend const API_BASE_URL = '/api'; // Create axios instance with default configuration const apiClient = axios.create({ baseURL: API_BASE_URL, timeout: 10000, headers: { 'Content-Type': 'application/json', }, }); // API Service Object const apiService = { // Camera endpoints getCameras: () => apiClient.get('/cameras'), addCamera: (cameraId, source) => apiClient.post('/cameras', null, { params: { camera_id: cameraId, source: source }, }), removeCamera: (cameraId) => apiClient.delete(`/cameras/${cameraId}`), getVideoFeed: (cameraId) => `/api/video_feed/${cameraId}`, // Identity endpoints getIdentities: () => apiClient.get('/identities'), createProfile: (globalId, name, metadata = null) => apiClient.post(`/profiles/${globalId}`, null, { params: { name, metadata }, }), getProfile: (globalId) => apiClient.get(`/profiles/${globalId}`), // Search endpoints findPerson: (imageFile) => { const formData = new FormData(); formData.append('image', imageFile); return apiClient.post('/find_person', formData, { headers: { 'Content-Type': 'multipart/form-data', }, }); }, // System endpoints getStats: () => apiClient.get('/stats'), getAnalytics: () => apiClient.get('/analytics'), // Alert endpoints getAlertRules: () => apiClient.get('/alerts/rules'), createAlertRule: (rule) => apiClient.post('/alerts/rules', rule), // WebSocket endpoint connectWebSocket: () => { const protocol = window.location.protocol === 'https:' ? 'wss' : 'ws'; const ws = new WebSocket(`${protocol}://${window.location.host}/api/ws`); return ws; }, }; export default apiService;