Skip to content

Commit

Permalink
feat(client): compat avatar server return
Browse files Browse the repository at this point in the history
  • Loading branch information
lizheming committed Jan 10, 2021
1 parent 1ab3c9f commit 86a0f0a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/client/src/components/CommentBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export default function({
) : (
<div className="vlogin-info">
<div className="vlogin-avatar">
<img src={ctx.gravatarSetting.cdn + ctx.userInfo.mailMd5 + ctx.gravatarSetting.params} alt="" className="vimg"/>
<img src={ctx.userInfo.avatar || ctx.gravatarSetting.cdn + ctx.userInfo.mailMd5 + ctx.gravatarSetting.params} alt="" className="vimg"/>
<div
title={ctx.locale.logout}
className="vlogin-logout-btn"
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/components/CommentCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function CommentCard({comment, boxConfig, rootId, onSubmit}) {
<div className="vcard" id={comment.objectId}>
<img
className="vimg"
src={ctx.gravatarSetting.cdn + comment.mail + ctx.gravatarSetting.params}
src={comment.avatar || ctx.gravatarSetting.cdn + comment.mail + ctx.gravatarSetting.params}
/>
<div className="vh">
<div className="vhead">
Expand Down
5 changes: 4 additions & 1 deletion packages/server/src/logic/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ module.exports = class extends think.Logic {

const user = await this.modelInstance.select(
{email: userMail},
{field: ['email', 'url', 'display_name', 'type', 'github']}
{field: ['email', 'url', 'display_name', 'type', 'github', 'avatar']}
);
if(!think.isEmpty(user)) {
const userInfo = user[0];
userInfo.mailMd5 = helper.md5(userInfo.email);
if(/(github)/i.test(userInfo.avatar)) {
userInfo.avatar = this.config('avatarProxy') + '?url=' + encodeURIComponent(userInfo.avatar);
}
this.ctx.state.userInfo = userInfo;
}
}
Expand Down

0 comments on commit 86a0f0a

Please sign in to comment.