diff --git a/src/routes/profile.js b/src/routes/profile.js index 720bb08ae..7272c0f16 100644 --- a/src/routes/profile.js +++ b/src/routes/profile.js @@ -23,6 +23,7 @@ const assert = require('assert'), HttpError = require('connect-lastmile').HttpError, HttpSuccess = require('connect-lastmile').HttpSuccess, safe = require('safetydance'), + superagent = require('superagent'), users = require('../users.js'); async function canEditProfile(req, res, next) { @@ -121,8 +122,15 @@ async function getAvatar(req, res, next) { const [error, avatar] = await safe(users.getAvatar(req.params.identifier)); if (error) return next(BoxError.toHttpError(error)); - res.set('Content-Type', 'image/png'); - res.send(avatar); + if (avatar === constants.AVATAR_GRAVATAR) { + superagent(gravatarUrl).pipe(`https://www.gravatar.com/avatar/${require('crypto').createHash('md5').update(user.email).digest('hex')}.jpg`); + } else if (avatar === constants.AVATAR_NONE) { + // res.set('Content-Type', 'image/png'); + // res.send(avatar); + } else { + res.set('Content-Type', 'image/png'); + res.send(avatar); + } } async function setBackgroundImage(req, res, next) {