import { UPLOAD_FILE, UPLOAD_HEADS, CASE_INFO } from './constant' import { axios } from './instance' import { jsonToForm } from '@/utils' import { params } from '@/env' type UploadFile = LocalFile | string export const blobToFile = (blob: Blob, suffix = '.png') => new File([blob], `aaa${suffix}`) export const uploadFile = async (file: UploadFile, suffix = '.png') => { if (typeof file === 'string') { return file } else { const uploadFile = file.blob instanceof File ? file.blob : blobToFile(file.blob, suffix) const url = await axios({ method: 'POST', url: UPLOAD_FILE, data: jsonToForm({ file: uploadFile }), headers: {...UPLOAD_HEADS} }) return url } } export interface Case { caseTitle: string } export const getCaseInfo = () => axios.get(CASE_INFO, { params: { caseId: params.caseId } })