sau / sau_frontend /src /api /material.js
skatef's picture
fix: 生产环境 API 同源,HF Space / Docker 前端可正常请求后端
a206d0f
raw
history blame contribute delete
815 Bytes
import { http } from '@/utils/request'
import { getApiBase } from '@/utils/apiBase'
// 素材管理API
export const materialApi = {
// 获取所有素材
getAllMaterials: () => {
return http.get('/getFiles')
},
// 上传素材
uploadMaterial: (formData, onUploadProgress) => {
// 使用http.upload方法,它已经配置了正确的Content-Type
return http.upload('/uploadSave', formData, onUploadProgress)
},
// 删除素材
deleteMaterial: (id) => {
return http.get(`/deleteFile?id=${id}`)
},
// 下载素材
downloadMaterial: (filePath) => {
const b = getApiBase()
return `${b}/download/${filePath}`
},
// 获取素材预览URL
getMaterialPreviewUrl: (filename) => {
const b = getApiBase()
return `${b}/getFile?filename=${filename}`
}
}