| 1 | import { http } from '@/utils/request' |
| 2 | |
| 3 | // 素材管理API |
| 4 | export const materialApi = { |
| 5 | // 获取所有素材 |
| 6 | getAllMaterials: () => { |
| 7 | return http.get('/getFiles') |
| 8 | }, |
| 9 | |
| 10 | // 上传素材 |
| 11 | uploadMaterial: (formData, onUploadProgress) => { |
| 12 | // 使用http.upload方法,它已经配置了正确的Content-Type |
| 13 | return http.upload('/uploadSave', formData, onUploadProgress) |
| 14 | }, |
| 15 | |
| 16 | // 删除素材 |
| 17 | deleteMaterial: (id) => { |
| 18 | return http.get(`/deleteFile?id=${id}`) |
| 19 | }, |
| 20 | |
| 21 | // 下载素材 |
| 22 | downloadMaterial: (filePath) => { |
| 23 | return `${import.meta.env.VITE_API_BASE_URL || 'http://localhost:5409'}/download/${filePath}` |
| 24 | }, |
| 25 | |
| 26 | // 获取素材预览URL |
| 27 | getMaterialPreviewUrl: (filename) => { |
| 28 | return `${import.meta.env.VITE_API_BASE_URL || 'http://localhost:5409'}/getFile?filename=${filename}` |
| 29 | } |
| 30 | } |