Skip to content

Commit

Permalink
HTTP status codes + enlargement disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugene Terentev committed Nov 10, 2017
1 parent 218cb00 commit b38cadb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jspm_packages/

# Lock
yarn.lock
package-lock.json

# Typescript v1 declaration files
typings/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lambda-images-resizer",
"version": "0.1.2",
"version": "0.1.5",
"description": "Lambda images resizing handler",
"main": "src/index.js",
"scripts": {
Expand Down
13 changes: 7 additions & 6 deletions src/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = function(options) {
return new Promise(function (fulfill, reject) {
Sharp(data.Body)
.resize(width, height)
.withoutEnlargement()
.toFormat(format)
.toBuffer(function(err, outputBuffer) {
if (err) reject(err)
Expand Down Expand Up @@ -60,32 +61,32 @@ module.exports = function(options) {
key = splitted_key[1];

if (!key) {
return reject(new HttpError('Unsupported image location'))
return reject(new HttpError('Unsupported image location', 421))
}

let match = key.match(/(\d+|auto)x(\d+|auto)\/(.*)/);

if(!match) {
return reject(new HttpError('Malformed route'));
return reject(new HttpError('Malformed route', 406));
}

let width = parseInt(match[1], 10);
let height = parseInt(match[2], 10);
let originalKey = match[3];

if (options.signatureVerification && (!signature || !signVerify(signature, match[1], match[2], match[3]))) {
return reject(new HttpError('Invalid signature'));
return reject(new HttpError('Invalid signature', 403));
}

if(isNaN(width) && isNaN(height)) {
reject(new HttpError('Invalid dimensions'));
reject(new HttpError('Invalid dimensions', 400));
}

if(isNaN(width)) width = null;
if(isNaN(height)) height = null;

if (width > options.maxWidth || height > options.maxHeight) {
return reject(new HttpError('Dimensions maximum constraint violation'));
return reject(new HttpError('Dimensions maximum constraint violation', 403));
}


Expand All @@ -94,7 +95,7 @@ module.exports = function(options) {
let mimeType = mime.getType(originalKey)

if (supportedTypes.indexOf(mimeType) === -1) {
return reject(new HttpError('Unsupported format'));
return reject(new HttpError('Unsupported format', 415));
}

return download(options.bucket, originalKey)
Expand Down

0 comments on commit b38cadb

Please sign in to comment.