From 80e83e0c05b44683b3196c5c10d791cd9832ecc2 Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Sat, 27 Jan 2024 22:55:10 +0100 Subject: [PATCH] Always send images for profile --- src/routes/profile.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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) {