Ghost/core/server/lib/image/gravatar.js
kirrg001 fc5b4dd934 Moved image utils to lib/image
refs #9178

- i am not super happy about `const imageLib = require('../lib/image')`
- i don't really like the name `imageLib`
- but i had no better idea 😃
- if we use the same name in the whole project, it's very easy to rename the folder or the variable
2017-12-14 20:46:53 +01:00

32 lines
934 B
JavaScript

var Promise = require('bluebird'),
crypto = require('crypto'),
config = require('../../config'),
request = require('../request');
module.exports.lookup = function lookup(userData, timeout) {
var gravatarUrl = '//www.gravatar.com/avatar/' +
crypto.createHash('md5').update(userData.email.toLowerCase().trim()).digest('hex') +
'?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
});
};