diff options
author | Sheogorath | 2018-06-23 23:40:46 +0200 |
---|---|---|
committer | Sheogorath | 2018-06-23 23:40:55 +0200 |
commit | 318b2d378f54805e99b7022db15136df7c920083 (patch) | |
tree | 2f7ea603b4b8c5423ebc07cdc9cc226c62aa1553 /lib/letter-avatars.js | |
parent | a2608c319a8c31f9b173dbb5d00221d3ad96739b (diff) |
Allow to disable gravatar
Since Gravatar is an external image source and not perfect from a
privacy perspective, forbidding it allows to improve privacy.
This commit also simplifies and optimizes the avatar code.
Signed-off-by: Sheogorath <sheogorath@shivering-isles.com>
Diffstat (limited to 'lib/letter-avatars.js')
-rw-r--r-- | lib/letter-avatars.js | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/letter-avatars.js b/lib/letter-avatars.js index b5b1d9e7..53fa011a 100644 --- a/lib/letter-avatars.js +++ b/lib/letter-avatars.js @@ -1,5 +1,6 @@ 'use strict' // external modules +const md5 = require('blueimp-md5') const randomcolor = require('randomcolor') const config = require('./config') @@ -24,6 +25,17 @@ exports.generateAvatar = function (name) { return svg } -exports.generateAvatarURL = function (name) { - return config.serverURL + '/user/' + name + '/avatar.svg' +exports.generateAvatarURL = function (name, email = '', big = true) { + let photo + if (email !== '' && config.allowGravatar) { + photo = 'https://www.gravatar.com/avatar/' + md5(email.toLowerCase()) + if (big) { + photo += '?s=400' + } else { + photo += '?s=96' + } + } else { + photo = config.serverURL + '/user/' + (name || email.substring(0, email.lastIndexOf('@')) || md5(email.toLowerCase())) + '/avatar.svg' + } + return photo } |