提交 84bfee97 编写于 作者: C chenruilong

fix(uni-id-co): 修复 微信登录时用户未设置头像的报错问题

上级 de9fd580
...@@ -120,28 +120,34 @@ module.exports = async function (params = {}) { ...@@ -120,28 +120,34 @@ module.exports = async function (params = {}) {
accessToken, accessToken,
openid openid
}) })
// eslint-disable-next-line n/no-deprecated-api
const avatarPath = url.parse(avatar).pathname if (avatar) {
const extName = avatarPath.indexOf('.') > -1 ? url.parse(avatar).pathname.split('.').pop() : 'jpg' // eslint-disable-next-line n/no-deprecated-api
const cloudPath = `user/avatar/${openid.slice(-8) + Date.now()}-avatar.${extName}` const avatarPath = url.parse(avatar).pathname
const getAvatarRes = await uniCloud.httpclient.request(avatar) const extName = avatarPath.indexOf('.') > -1 ? url.parse(avatar).pathname.split('.').pop() : 'jpg'
if (getAvatarRes.status >= 400) { const cloudPath = `user/avatar/${openid.slice(-8) + Date.now()}-avatar.${extName}`
throw { const getAvatarRes = await uniCloud.httpclient.request(avatar)
errCode: ERROR.GET_THIRD_PARTY_USER_INFO_FAILED if (getAvatarRes.status >= 400) {
throw {
errCode: ERROR.GET_THIRD_PARTY_USER_INFO_FAILED
}
}
const {
fileID
} = await uniCloud.uploadFile({
cloudPath,
fileContent: getAvatarRes.data
})
extraData.avatar_file = {
name: cloudPath,
extname: extName,
url: fileID
} }
} }
const {
fileID
} = await uniCloud.uploadFile({
cloudPath,
fileContent: getAvatarRes.data
})
extraData.nickname = nickname extraData.nickname = nickname
extraData.avatar_file = {
name: cloudPath,
extname: extName,
url: fileID
}
} }
await saveWeixinUserKey.call(this, { await saveWeixinUserKey.call(this, {
openid, openid,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册