Skip to content

Commit 7a83fc0

Browse files
authored
Merge pull request #1110 from dsprenkels/issue_1106
Remove blueimp-md5 dependency
2 parents dba9575 + f7bc1e9 commit 7a83fc0

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

lib/letter-avatars.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22
// external modules
3-
const md5 = require('blueimp-md5')
3+
const crypto = require('crypto')
44
const randomcolor = require('randomcolor')
55
const config = require('./config')
66

@@ -31,15 +31,19 @@ exports.generateAvatarURL = function (name, email = '', big = true) {
3131
email = '' + name + '@example.com'
3232
}
3333

34+
let hash = crypto.createHash('md5')
35+
hash.update(email.toLowerCase())
36+
let hexDigest = hash.digest('hex')
37+
3438
if (email !== '' && config.allowGravatar) {
35-
photo = 'https://www.gravatar.com/avatar/' + md5(email.toLowerCase())
39+
photo = 'https://www.gravatar.com/avatar/' + hexDigest;
3640
if (big) {
3741
photo += '?s=400'
3842
} else {
3943
photo += '?s=96'
4044
}
4145
} else {
42-
photo = config.serverURL + '/user/' + (name || email.substring(0, email.lastIndexOf('@')) || md5(email.toLowerCase())) + '/avatar.svg'
46+
photo = config.serverURL + '/user/' + (name || email.substring(0, email.lastIndexOf('@')) || hexDigest) + '/avatar.svg'
4347
}
4448
return photo
4549
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "app.js",
66
"license": "AGPL-3.0",
77
"scripts": {
8-
"test": "npm run-script eslint && npm run-script jsonlint",
8+
"test": "npm run-script eslint && npm run-script jsonlint && mocha",
99
"eslint": "node_modules/.bin/eslint lib public app.js",
1010
"jsonlint": "find . -not -path './node_modules/*' -type f -name '*.json' -o -type f -name '*.json.example' | while read json; do echo $json ; jq . $json; done",
1111
"standard": "echo 'standard is no longer being used, use `npm run eslint` instead!' && exit 1",
@@ -23,7 +23,6 @@
2323
"aws-sdk": "^2.345.0",
2424
"azure-storage": "^2.7.0",
2525
"base64url": "^3.0.0",
26-
"blueimp-md5": "^2.6.0",
2726
"body-parser": "^1.15.2",
2827
"bootstrap": "^3.3.7",
2928
"bootstrap-validator": "^0.11.8",
@@ -184,6 +183,7 @@
184183
"less": "^2.7.1",
185184
"less-loader": "^4.1.0",
186185
"mini-css-extract-plugin": "^0.4.1",
186+
"mocha": "^5.2.0",
187187
"optimize-css-assets-webpack-plugin": "^5.0.0",
188188
"script-loader": "^0.7.2",
189189
"string-loader": "^0.0.1",

test/letter-avatars.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict'
2+
3+
const assert = require('assert');
4+
const avatars = require('../lib/letter-avatars')
5+
6+
describe('generateAvatarURL()', function() {
7+
it('should return correct urls', function() {
8+
assert.equal(avatars.generateAvatarURL('Daan Sprenkels', '[email protected]', true), 'https://www.gravatar.com/avatar/d41b5f3508cc3f31865566a47dd0336b?s=400');
9+
assert.equal(avatars.generateAvatarURL('Daan Sprenkels', '[email protected]', false), 'https://www.gravatar.com/avatar/d41b5f3508cc3f31865566a47dd0336b?s=96');
10+
});
11+
});

0 commit comments

Comments
 (0)