import { RcFile } from 'antd/es/upload'; import API from './request'; import { videoApi } from './video'; export const imageApi = { uploadImage: async (file) => { const data = new FormData(); data.append('file', file); const res = await API.imageClient.post('/upload/image', data, { headers: { 'Content-Type': 'multipart/form-data', }, params: { cloud: true, }, }); return res.data; }, uploadImageByURL: async (url) => { const res = await API.builderBffClient.post('/v1/upload/image', { url, }); return res.data; }, }; export const uploadFileHandler = async ( file: string | RcFile | Blob, type: 'image' | 'url' | 'video' | 'videoUrl', ): Promise => { let res; switch (type) { case 'image': res = await imageApi.uploadImage(file); return res?.image_url; case 'video': res = await videoApi.uploadVideo(file); return res?.url; case 'videoUrl': res = await videoApi.uploadVideoByURL(file); return res?.videoUrl; default: res = await imageApi.uploadImageByURL(file); return res?.imageUrl; } };