Spaces:
Running
Running
| import axios from 'axios'; | |
| // Ensure the local storage runs conditionally on the client | |
| const getToken = () => { | |
| if (typeof window !== 'undefined') { | |
| return localStorage.getItem('access_token'); | |
| } | |
| return null; | |
| }; | |
| export const api = axios.create({ | |
| baseURL: process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000', | |
| withCredentials: true | |
| }); | |
| api.interceptors.request.use((config) => { | |
| const token = getToken(); | |
| if (token) { | |
| config.headers.Authorization = `Bearer ${token}`; | |
| } | |
| return config; | |
| }); | |
| export const apiLayer = { | |
| // Auth Lookups | |
| getCurrentUser: () => api.get('/auth/me'), | |
| // Dashboard Metrics | |
| getUserFiles: () => api.get('/files/my-files'), | |
| deleteFile: (id: string) => api.delete(`/files/${id}`), | |
| // Result Processing | |
| getFileById: (id: string) => api.get(`/files/${id}`), | |
| // Profile updates | |
| updateAvatar: (avatar_url: string) => api.put('/profile/avatar', { avatar_url }), | |
| updateUsername: (username: string) => api.put('/profile/username', { username }), | |
| // Feedback | |
| submitFeedback: (data: { file_id: number, label: string, confidence: number, freq_score: number, cnn_score: number }) => api.post('/feedback/', data), | |
| // Account deletion | |
| deleteAccount: () => api.delete('/users/delete') | |
| }; | |