import axios from '@/utils/http';
const base = process.env.VUE_APP_SERVER + '/file';
function getFileSuffix(file: File) {
    const fileName = file.name;
    const index = fileName.lastIndexOf('.');
    return fileName.substr(index + 1);
}
export default {
    upload(file: File, cb: (progressEvent: any) => void = (progressEvent: any) => progressEvent) {
        const suffix = getFileSuffix(file);
        const formData = new FormData();
        formData.append('file_data', file);
        return axios({
            url: `${base}/upload?file_type=${suffix}`,
            method: 'post',
            headers: { 'Content-Type': 'multipart/form-data' },
            data: formData,
            onUploadProgress:  (progressEvent) => {
                // 对原生进度事件的处理
                cb(progressEvent);
            },
            timeout: 0,
        });
    },
    getFiles(hashes: string[], params: any) {
        return axios.post(`${base}/getFiles`, {
            hashes,
            ...params,
        });
    },
};
