Skip to content

Commit

Permalink
choose preferred profile picture format automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
zerodytrash committed Aug 20, 2022
1 parent 9f67625 commit 2313d27
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/lib/webcastDataConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function getUserAttributes(webcastUser) {
secUid: webcastUser.secUid?.toString(),
uniqueId: webcastUser.uniqueId !== '' ? webcastUser.uniqueId : undefined,
nickname: webcastUser.nickname !== '' ? webcastUser.nickname : undefined,
profilePictureUrl: webcastUser.profilePicture?.urls[2],
profilePictureUrl: getPreferredPictureFormat(webcastUser.profilePicture?.urls),
followRole: webcastUser.followInfo?.followStatus,
userBadges: mapBadges(webcastUser.badges),
userDetails: {
Expand Down Expand Up @@ -204,6 +204,19 @@ function mapBadges(badges) {
return simplifiedBadges;
}

function getPreferredPictureFormat(pictureUrls) {
if (!pictureUrls || !Array.isArray(pictureUrls) || !pictureUrls.length) {
return null;
}

return (
pictureUrls.find((x) => x.includes('100x100') && x.includes('.webp')) ||
pictureUrls.find((x) => x.includes('100x100') && x.includes('.jpeg')) ||
pictureUrls.find((x) => !x.includes('shrink')) ||
pictureUrls[0]
);
}

module.exports = {
simplifyObject,
};

0 comments on commit 2313d27

Please sign in to comment.