Spaces:
Running
Running
File size: 1,327 Bytes
67264dd 8a0d65c 67264dd ee2facf a16341c 67264dd | 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 | 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')
};
|