Skip to content

Commit c49183e

Browse files
authored
Merge pull request #72 from Jackymancs4-Fork/feature/custom-size-endpoint
Added optional size parameter to custom faces endpoint in JS Closes #41
2 parents 3da640f + cafa178 commit c49183e

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ Assuming your server lives at `myserver.com`, and you've configured the middlewa
3636
* `myserver.com/myAvatars/:size/:id`
3737
* returns an avatar for the provided `id` at the specified `size`
3838
* size cannot exceed 400px
39-
* `myserver.com/myAvatars/face/:eyes/:nose/:mouth/:color`
39+
* `myserver.com/myAvatars/face/:eyes/:nose/:mouth/:color/:size?`
4040
* Allows you to generate a custom avatar from the specified parts and color
4141
* e.g. `myserver.com/myAvatars/face/eyes1/nose2/mouth4/DEADBF`
42+
* You can also set the size of your custom avatar
43+
* e.g. `myserver.com/myAvatars/face/eyes1/nose2/mouth4/DEADBF/300`
4244
* `myserver.com/myAvatars/list`
4345
* returns JSON of all valid parts for the custom endpoint above
4446

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)