const cloud = require('wx-server-sdk')
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
})
const JSZip = require('jszip')
const db = cloud.database()
const devName=["断路器","隔离开关","接地刀闸","主变","电容电抗器","发电机","电压互感器"]
exports.main = async (event, context) => {
const zip=new JSZip()
let data = await db.collection('d_task').doc(event.taskId).get().then(res => res.data)
let subName = data.sub_name
let devs = data.devs
let zipFile=subName+event.date+'.zip'
for(var i=0;i<devs.length;i++){
let e=devs[i]
if(e.length>0){
let dir=zip.folder(devName[i])
for(var j=0;j<e.length;j++){
let f=e[j]
if (f.fileId) {
let res=await cloud.downloadFile({fileID:f.fileId})
dir.file(f.name+`${f.fileId.match(/\.[^.]+?$/)[0]}`,res.fileContent)
}
}
}
}
const content = await zip.generateAsync({ type: 'nodebuffer' })
const res = await cloud.uploadFile({
cloudPath: 'mp_data/'+event.taskId+'/'+zipFile,
fileContent: content,
})
const result=await cloud.getTempFileURL({
fileList: [res.fileID],
maxAge:3600
})
return {
zipFile,
zipUrl:result.fileList[0].tempFileURL
}
}
我用云函数打包云存储里的图片,当图片超过一定数量的时候,即使云函数设置了最长时限60秒,云函数会报超时,执行失败,请问有什么好的办法解决此问题?
可以最长设置为600秒。