const cloud = require('wx-server-sdk')
const pdf = require('pdf-poppler')
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV })
exports.main = async (event, context) => {
const wxContext = cloud.getWXContext()
cloudID = ""
let opts = {
format: 'jpeg',
out_dir: '/',
out_prefix: event.fileName,
page: null
}
pdf.convert(event.filePath, opts)
wx.cloud.uploadFile({
cloudPath: event.fileName + '.jpeg',
filePath: event.fileName + '.jpeg'
}).then(res => {
cloudID = res.fileID
}).catch(res => {
console.log(res)
})
return {
event,
openid: wxContext.OPENID,
appid: wxContext.APPID,
unionid: wxContext.UNIONID,
cloudid: cloudID,
}
}