const wxacodeResult = await cloud.openapi.wxacode.get({
path: event.path || 'pages/index/index',
})
const fileExtensionMatches = wxacodeResult.contentType.match(/\/([^\/]+)/)
const fileExtension = (fileExtensionMatches && fileExtensionMatches[1]) || 'jpg'
const { OPENID } = cloud.getWXContext()
console.log(`${OPENID}.${fileExtension}`)
const uploadResult = await cloud.uploadFile({
cloudPath: `${OPENID}.${fileExtension}`,
fileContent: wxacodeResult.buffer,
})
if (!uploadResult.fileID) {
throw new Error(`upload failed with empty fileID and storage server status code ${uploadResult.statusCode}`)
}
return uploadResult.fileID