44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import axios from 'axios';
|
|
import { File, FileUploadResponse } from '../types/file';
|
|
|
|
const API_BASE_URL = process.env.REACT_APP_API_BASE_URL || 'http://localhost:8000/api/v1';
|
|
|
|
// Create axios instance with default config
|
|
const axiosInstance = axios.create({
|
|
baseURL: API_BASE_URL,
|
|
timeout: 30000, // 30 seconds timeout
|
|
});
|
|
|
|
export const api = {
|
|
uploadFile: async (file: globalThis.File): Promise<FileUploadResponse> => {
|
|
const formData = new FormData();
|
|
formData.append('file', file);
|
|
const response = await axiosInstance.post('/files/upload', formData, {
|
|
headers: {
|
|
'Content-Type': 'multipart/form-data',
|
|
},
|
|
});
|
|
return response.data;
|
|
},
|
|
|
|
listFiles: async (): Promise<File[]> => {
|
|
const response = await axiosInstance.get('/files/files');
|
|
return response.data;
|
|
},
|
|
|
|
getFile: async (fileId: string): Promise<File> => {
|
|
const response = await axiosInstance.get(`/files/files/${fileId}`);
|
|
return response.data;
|
|
},
|
|
|
|
downloadFile: async (fileId: string): Promise<Blob> => {
|
|
const response = await axiosInstance.get(`/files/files/${fileId}/download`, {
|
|
responseType: 'blob',
|
|
});
|
|
return response.data;
|
|
},
|
|
|
|
deleteFile: async (fileId: string): Promise<void> => {
|
|
await axiosInstance.delete(`/files/files/${fileId}`);
|
|
},
|
|
};
|