Fix GitHub's avatar URL

At the moment, the URL is being composed and modified with the use of
string composition.

This causes issues, if the URL returned by GitHub slightly differs from
the time developer initially had a look into it.

In our case, the URL from GitHub has two query parameters in it, whilst
the codebase only expected one.

This change will take all of these parameters and only set the one we
care about, whilst leaving others intact and carry on with the full URL.

Fixes #1489

Signed-off-by: Rafal Proszowski <paroxp@gmail.com>
This commit is contained in:
Rafal Proszowski 2020-04-20 12:18:25 +01:00 committed by Rafal Proszowski
parent d7cc95129d
commit e1977a1da7
No known key found for this signature in database
GPG Key ID: C4CE726F8465B7FC
1 changed files with 5 additions and 4 deletions

View File

@ -115,10 +115,11 @@ module.exports = function (sequelize, DataTypes) {
else photo += '?size=bigger'
break
case 'github':
if (profile.photos && profile.photos[0]) photo = profile.photos[0].value.replace('?', '')
else photo = 'https://avatars.githubusercontent.com/u/' + profile.id
if (bigger) photo += '?s=400'
else photo += '?s=96'
const photoURL = new URL(profile.photos && profile.photos[0]
? profile.photos[0].value
: `https://avatars.githubusercontent.com/u/${profile.id}`)
photoURL.searchParams.set('s', bigger ? 400 : 96)
photo = photoURL.toString()
break
case 'gitlab':
photo = profile.avatarUrl