import {
	getOssUploadParams
} from "@/api/api.js"



export const uploadFiles = (urls) => {
	return new Promise(async (resolve, reject) => {
		let res = await getOssUploadParams()
		const fd = {
			policy: res.policy,
			OSSAccessKeyId: res.accessId,
			success_action_status: 200,
			signature: res.signature,
			key: res.dir + Date.now() + Math.floor(100000 + Math.random() *
					900000) + '.' +
				urls.substring(urls.lastIndexOf(".") + 1),
		};
		uni.uploadFile({
			url: res.host, // Example, not a real endpoint
			filePath: urls,
			header: {
				"content-type": 'multipart/form-data'
			},
			name: 'file',
			formData: fd,
			success: (_res) => {
				resolve(fd.key);
			},
			fail: (err) => {
				console.log(err);
				reject(err);
			}
		});
		console.log();
	});
}