import { getUploadToken } from "@/api/common";
import axios from "axios";
// const dayjs = require('dayjs')
import dayjs from "dayjs";
/* 文件上传 */
export const uploadFiles = async tempFiles => {
    const resToken = await getUploadToken();
    const plist = [];
    tempFiles.forEach(file => {
        console.log(file);
        const nowDate = dayjs(new Date()).format("YYYY-MM-DD");
        const suffix = file.type.indexOf("image") != -1 ? ".jpg" : ".mp4";
        const key = `v2MpPublishMedia/${nowDate}/${new Date().getTime()}${suffix}`;
        const formData = new FormData();
        formData.append("token", resToken.data);
        formData.append("key", key);
        formData.append("file", file);
        plist.push(
            new Promise((resolve, reject) => {
                axios
                    .post("https://up-z2.qiniup.com", formData)
                    .then(res => {
                        resolve(res.data);
                    })
                    .catch(err => {
                        reject(err);
                    });
            })
        );
    });
    return Promise.all(plist);
};
