Skip to content

Commit a0f6bb4

Browse files
committed
Merge branch 'feature/custom-size-endpoint' into develop
2 parents 3da640f + 25a6e5c commit a0f6bb4

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/lib/imager.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ const _parseSize = (size) => {
2222
};
2323

2424
export const combine = (face, size, callback) => {
25-
if (callback) { size = _parseSize(size); }
25+
if (size) { size = _parseSize(size); }
2626
else {
27-
callback = size;
2827
size = { width: maxSize, height: maxSize };
2928
}
3029

src/routes/avatars.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ router.get('/list', function(req, res) {
3131
});
3232

3333
router.get('/:id', function(req, res, next) {
34-
return combine(req.faceParts, function(err, stdout) {
34+
return combine(req.faceParts,false, function(err, stdout) {
3535
return common.sendImage(err, stdout, req, res, next);
3636
});
3737
});
@@ -42,7 +42,7 @@ router.get('/:size/:id', function(req, res, next) {
4242
});
4343
});
4444

45-
router.get('/face/:eyes/:nose/:mouth/:color', function(req, res, next) {
45+
router.get('/face/:eyes/:nose/:mouth/:color/:size?', function(req, res, next) {
4646
let faceParts = { color: '#' + req.params.color };
4747

4848
partTypes.forEach(function(type) {
@@ -61,7 +61,7 @@ router.get('/face/:eyes/:nose/:mouth/:color', function(req, res, next) {
6161
faceParts[type] = pathFor(type, fileName);
6262
});
6363

64-
return combine(faceParts, function(err, stdout) {
64+
return combine(faceParts, req.params.size, function(err, stdout) {
6565
return common.sendImage(err, stdout, req, res, next);
6666
});
6767
});

test/integration.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ describe('routing', function() {
4545
.expect('Content-Type', /image/)
4646
.end(done);
4747
});
48+
49+
it('can manually compose an image with a custom size', function(done) {
50+
request.get('/avatars/face/eyes1/nose4/mouth11/bbb/50')
51+
.expect(200)
52+
.expect('Content-Type', /image/)
53+
.parse(parseImage).end(function(err, res) {
54+
im(res.body).size(function(_, size) {
55+
expect(size).to.eql({ height: 50, width: 50 });
56+
done();
57+
});
58+
});
59+
});
4860
});
4961

5062
describe('v2 avatar list requests', function() {

0 commit comments

Comments
 (0)