Skip to content

Commit

Permalink
Router default avatar path
Browse files Browse the repository at this point in the history
  • Loading branch information
liyachuan committed Apr 24, 2014
1 parent cba1959 commit dae8177
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,20 @@ exports.toUser = function(req, res) {
});
};

var _sendImg = function(req, res, file, type) {
res.writeHead(200, {'Content-Type': 'image/' + type });
res.end(file, 'binary');
};

var _defaultAvatar = './public/img/wx_logo.png';

exports.getAvatar = function(req, res) {
var name = req.params.name;
var img = fs.readFileSync('./public/avatar/' + name + '.png');
res.writeHead(200, {'Content-Type': 'image/png' });
res.end(img, 'binary');
fs.readFile('./public/avatar/' + req.params.name + '.png', function(err, file) {
if(err) {
return fs.readFile(_defaultAvatar, function(err, file) {
_sendImg(req, res, file, 'png');
})
}
_sendImg(req, res, file, 'png');
});
};
2 changes: 1 addition & 1 deletion views/include/user-avatar.jade
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ a.circle-img(href='/u/#{author.name}')
.img.circle-img-show
img.avatar-max(src="/avatar/#{author.name}")
.circle-img-info
.circle-img-info-text 李亚川Apple
.circle-img-info-text #{author.name}

0 comments on commit dae8177

Please sign in to comment.