Merge branch 'hotfix/21.56.9' into master
[gitter.git] / server / api / private / user-avatar.js
blob252db8e35e0b61efd79bb5e65a6eb7ced69d0003
1 'use strict';
3 var resolveUserAvatarUrl = require('gitter-web-shared/avatars/resolve-user-avatar-url');
4 var userService = require('gitter-web-users');
6 var DEFAULT_AVATAR_URL = 'https://avatars1.githubusercontent.com/u/0';
8 function resolveAvatarForUsername(req, res) {
9   var username = req.params.username;
10   var size = parseInt(req.query.s, 10) || 60;
12   return userService.findByUsername(username).then(function(user) {
13     var url;
14     if (user) {
15       url = resolveUserAvatarUrl(user, size);
16       if (url.indexOf('/api/private/user-avatar/') !== -1) {
17         // don't keep redirecting back here in a loop..
18         url = DEFAULT_AVATAR_URL;
19       }
20     } else {
21       url = DEFAULT_AVATAR_URL;
22     }
23     res.redirect(url);
24   });
27 module.exports = resolveAvatarForUsername;