Skip to content

Commit 8cfbfa4

Browse files
committed
Update to add biggerphoto on parsing user profile
1 parent ef0ac77 commit 8cfbfa4

1 file changed

Lines changed: 26 additions & 10 deletions

File tree

lib/models/user.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,39 +79,54 @@ module.exports = function (sequelize, DataTypes) {
7979
if (profile) {
8080
profile = {
8181
name: profile.displayName || profile.username,
82-
photo: User.parsePhotoByProfile(profile)
82+
photo: User.parsePhotoByProfile(profile),
83+
biggerphoto: User.parsePhotoByProfile(profile, true)
8384
}
8485
}
8586
return profile;
8687
},
87-
parsePhotoByProfile: function (profile) {
88+
parsePhotoByProfile: function (profile, bigger) {
8889
var photo = null;
8990
switch (profile.provider) {
9091
case "facebook":
91-
photo = 'https://graph.facebook.com/' + profile.id + '/picture?width=96';
92+
photo = 'https://graph.facebook.com/' + profile.id + '/picture';
93+
if (bigger) photo += '?width=400';
94+
else photo += '?width=96';
9295
break;
9396
case "twitter":
94-
photo = 'https://twitter.com/' + profile.username + '/profile_image?size=bigger';
97+
photo = 'https://twitter.com/' + profile.username + '/profile_image';
98+
if (bigger) photo += '?size=original';
99+
else photo += '?size=bigger';
95100
break;
96101
case "github":
97-
photo = 'https://avatars.githubusercontent.com/u/' + profile.id + '?s=96';
102+
photo = 'https://avatars.githubusercontent.com/u/' + profile.id;
103+
if (bigger) photo += '?s=400';
104+
else photo += '?s=96';
98105
break;
99106
case "gitlab":
100-
photo = profile.avatarUrl.replace(/(\?s=)\d*$/i, '$196');
107+
photo = profile.avatarUrl;
108+
if (bigger) photo.replace(/(\?s=)\d*$/i, '$1400');
109+
else photo.replace(/(\?s=)\d*$/i, '$196');
101110
break;
102111
case "dropbox":
103112
//no image api provided, use gravatar
104-
photo = 'https://www.gravatar.com/avatar/' + md5(profile.emails[0].value) + '?s=96';
113+
photo = 'https://www.gravatar.com/avatar/' + md5(profile.emails[0].value);
114+
if (bigger) photo += '?s=400';
115+
else photo += '?s=96';
105116
break;
106117
case "google":
107-
photo = profile.photos[0].value.replace(/(\?sz=)\d*$/i, '$196');
118+
photo = profile.photos[0].value;
119+
if (bigger) photo.replace(/(\?sz=)\d*$/i, '$1400');
120+
else photo.replace(/(\?sz=)\d*$/i, '$196');
108121
break;
109122
case "ldap":
110123
//no image api provided,
111124
//use gravatar if email exists,
112125
//otherwise generate a letter avatar
113126
if (profile.emails[0]) {
114-
photo = 'https://www.gravatar.com/avatar/' + md5(profile.emails[0]) + '?s=96';
127+
photo = 'https://www.gravatar.com/avatar/' + md5(profile.emails[0]);
128+
if (bigger) photo += '?s=400';
129+
else photo += '?s=96';
115130
} else {
116131
photo = letterAvatars(profile.username);
117132
}
@@ -123,7 +138,8 @@ module.exports = function (sequelize, DataTypes) {
123138
var photoUrl = 'https://www.gravatar.com/avatar/' + md5(email);
124139
return {
125140
name: email.substring(0, email.lastIndexOf("@")),
126-
photo: photoUrl += '?s=96'
141+
photo: photoUrl += '?s=96',
142+
biggerphoto: photoUrl += '?s=400'
127143
};
128144
}
129145
}

0 commit comments

Comments
 (0)