2020-04-29 18:44:27 +03:00
|
|
|
const Promise = require('bluebird');
|
|
|
|
const crypto = require('crypto');
|
2020-05-27 20:47:53 +03:00
|
|
|
const config = require('../../../shared/config');
|
2020-04-29 18:44:27 +03:00
|
|
|
const request = require('../request');
|
2016-02-12 23:04:26 +03:00
|
|
|
|
|
|
|
module.exports.lookup = function lookup(userData, timeout) {
|
2020-04-29 18:44:27 +03:00
|
|
|
let gravatarUrl = '//www.gravatar.com/avatar/' +
|
2016-02-12 23:04:26 +03:00
|
|
|
crypto.createHash('md5').update(userData.email.toLowerCase().trim()).digest('hex') +
|
2017-12-14 12:51:05 +03:00
|
|
|
'?s=250';
|
|
|
|
|
|
|
|
if (config.isPrivacyDisabled('useGravatar')) {
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
|
|
|
return request('https:' + gravatarUrl + '&d=404&r=x', {timeout: timeout || 2 * 1000})
|
|
|
|
.then(function () {
|
|
|
|
gravatarUrl += '&d=mm&r=x';
|
|
|
|
|
|
|
|
return {
|
|
|
|
image: gravatarUrl
|
|
|
|
};
|
|
|
|
})
|
|
|
|
.catch({statusCode: 404}, function () {
|
|
|
|
return {
|
|
|
|
image: undefined
|
|
|
|
};
|
|
|
|
})
|
|
|
|
.catch(function () {
|
|
|
|
// ignore error, just resolve with no image url
|
2016-02-12 23:04:26 +03:00
|
|
|
});
|
|
|
|
};
|