From 8cfbfa43520a298637b6f4e3137e4dea9d09e34d Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Fri, 3 Feb 2017 21:48:36 +0800 Subject: Update to add biggerphoto on parsing user profile --- lib/models/user.js | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'lib/models') diff --git a/lib/models/user.js b/lib/models/user.js index 7d27242c..aee42041 100644 --- a/lib/models/user.js +++ b/lib/models/user.js @@ -79,39 +79,54 @@ module.exports = function (sequelize, DataTypes) { if (profile) { profile = { name: profile.displayName || profile.username, - photo: User.parsePhotoByProfile(profile) + photo: User.parsePhotoByProfile(profile), + biggerphoto: User.parsePhotoByProfile(profile, true) } } return profile; }, - parsePhotoByProfile: function (profile) { + parsePhotoByProfile: function (profile, bigger) { var photo = null; switch (profile.provider) { case "facebook": - photo = 'https://graph.facebook.com/' + profile.id + '/picture?width=96'; + photo = 'https://graph.facebook.com/' + profile.id + '/picture'; + if (bigger) photo += '?width=400'; + else photo += '?width=96'; break; case "twitter": - photo = 'https://twitter.com/' + profile.username + '/profile_image?size=bigger'; + photo = 'https://twitter.com/' + profile.username + '/profile_image'; + if (bigger) photo += '?size=original'; + else photo += '?size=bigger'; break; case "github": - photo = 'https://avatars.githubusercontent.com/u/' + profile.id + '?s=96'; + photo = 'https://avatars.githubusercontent.com/u/' + profile.id; + if (bigger) photo += '?s=400'; + else photo += '?s=96'; break; case "gitlab": - photo = profile.avatarUrl.replace(/(\?s=)\d*$/i, '$196'); + photo = profile.avatarUrl; + if (bigger) photo.replace(/(\?s=)\d*$/i, '$1400'); + else photo.replace(/(\?s=)\d*$/i, '$196'); break; case "dropbox": //no image api provided, use gravatar - photo = 'https://www.gravatar.com/avatar/' + md5(profile.emails[0].value) + '?s=96'; + photo = 'https://www.gravatar.com/avatar/' + md5(profile.emails[0].value); + if (bigger) photo += '?s=400'; + else photo += '?s=96'; break; case "google": - photo = profile.photos[0].value.replace(/(\?sz=)\d*$/i, '$196'); + photo = profile.photos[0].value; + if (bigger) photo.replace(/(\?sz=)\d*$/i, '$1400'); + else photo.replace(/(\?sz=)\d*$/i, '$196'); break; case "ldap": //no image api provided, //use gravatar if email exists, //otherwise generate a letter avatar if (profile.emails[0]) { - photo = 'https://www.gravatar.com/avatar/' + md5(profile.emails[0]) + '?s=96'; + photo = 'https://www.gravatar.com/avatar/' + md5(profile.emails[0]); + if (bigger) photo += '?s=400'; + else photo += '?s=96'; } else { photo = letterAvatars(profile.username); } @@ -123,7 +138,8 @@ module.exports = function (sequelize, DataTypes) { var photoUrl = 'https://www.gravatar.com/avatar/' + md5(email); return { name: email.substring(0, email.lastIndexOf("@")), - photo: photoUrl += '?s=96' + photo: photoUrl += '?s=96', + biggerphoto: photoUrl += '?s=400' }; } } -- cgit v1.2.3 From 0a7adaf35d07efa658c040e789967acdc2eb32ff Mon Sep 17 00:00:00 2001 From: NV Date: Thu, 9 Feb 2017 13:24:40 +0900 Subject: Add default permission config --- lib/models/note.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/models') diff --git a/lib/models/note.js b/lib/models/note.js index 86112973..8b38d3f9 100644 --- a/lib/models/note.js +++ b/lib/models/note.js @@ -513,10 +513,10 @@ module.exports = function (sequelize, DataTypes) { } } } - // if no permission specified and have owner then give editable permission, else default permission is freely + // if no permission specified and have owner then give default permission in config, else default permission is freely if (!note.permission) { if (note.ownerId) { - note.permission = "editable"; + note.permission = config.defaultpermission; } else { note.permission = "freely"; } -- cgit v1.2.3 From 2aee0f267c2154ddf001507a62e4fe548515cd3a Mon Sep 17 00:00:00 2001 From: Wu Cheng-Han Date: Sat, 18 Feb 2017 20:07:15 +0800 Subject: Fix user profile photo might not replace to proper size --- lib/models/user.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/models') diff --git a/lib/models/user.js b/lib/models/user.js index aee42041..dd93bf78 100644 --- a/lib/models/user.js +++ b/lib/models/user.js @@ -105,8 +105,8 @@ module.exports = function (sequelize, DataTypes) { break; case "gitlab": photo = profile.avatarUrl; - if (bigger) photo.replace(/(\?s=)\d*$/i, '$1400'); - else photo.replace(/(\?s=)\d*$/i, '$196'); + if (bigger) photo = photo.replace(/(\?s=)\d*$/i, '$1400'); + else photo = photo.replace(/(\?s=)\d*$/i, '$196'); break; case "dropbox": //no image api provided, use gravatar @@ -116,8 +116,8 @@ module.exports = function (sequelize, DataTypes) { break; case "google": photo = profile.photos[0].value; - if (bigger) photo.replace(/(\?sz=)\d*$/i, '$1400'); - else photo.replace(/(\?sz=)\d*$/i, '$196'); + if (bigger) photo = photo.replace(/(\?sz=)\d*$/i, '$1400'); + else photo = photo.replace(/(\?sz=)\d*$/i, '$196'); break; case "ldap": //no image api provided, -- cgit v1.2.3