import axios from '@/utils/http';
const base = process.env.VUE_APP_SERVER + '/file';
export default {
    upload(file: File, cb: (progressEvent: any) => void = (progressEvent: any) => progressEvent) {
        const formData = new FormData();
        const filename = file.name;
        const index = filename.lastIndexOf('.');
        const suffix = filename.substr(index + 1);
        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,
        });
    },
};
