From ac2e8527d14ec5916e02a5e9b1c074c25ae02db1 Mon Sep 17 00:00:00 2001 From: Levi Wilson Date: Fri, 5 Jul 2019 15:20:04 -0400 Subject: [PATCH 1/4] fixes #116 by allowing the outputFormat to be specified on the request in Default mode --- .gitignore | 4 +++- source/image-handler/image-request.js | 7 ++++++- source/image-handler/test/test-image-request.js | 5 +++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 4ef6fdad0..e035d2539 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ # System Files -**/.DS_Store \ No newline at end of file +**/.DS_Store +deployment/{dist +deployment/manifest-generator diff --git a/source/image-handler/image-request.js b/source/image-handler/image-request.js index 75b7da7e7..9260a2bb9 100644 --- a/source/image-handler/image-request.js +++ b/source/image-handler/image-request.js @@ -26,6 +26,11 @@ class ImageRequest { this.bucket = this.parseImageBucket(event, this.requestType); this.key = this.parseImageKey(event, this.requestType); this.edits = this.parseImageEdits(event, this.requestType); + + if (this.requestType === 'Default') { + this.outputFormat = this.decodeRequest(event).outputFormat; + } + this.originalImage = await this.getOriginalImage(this.bucket, this.key) return Promise.resolve(this); } catch (err) { @@ -235,4 +240,4 @@ class ImageRequest { } // Exports -module.exports = ImageRequest; \ No newline at end of file +module.exports = ImageRequest; diff --git a/source/image-handler/test/test-image-request.js b/source/image-handler/test/test-image-request.js index 122da5552..c54b0dde0 100644 --- a/source/image-handler/test/test-image-request.js +++ b/source/image-handler/test/test-image-request.js @@ -23,7 +23,7 @@ describe('setup()', function() { the ImageRequest object with the proper values`, async function() { // Arrange const event = { - path : '/eyJidWNrZXQiOiJ2YWxpZEJ1Y2tldCIsImtleSI6InZhbGlkS2V5IiwiZWRpdHMiOnsiZ3JheXNjYWxlIjp0cnVlfX0=' + path : '/eyJidWNrZXQiOiJ2YWxpZEJ1Y2tldCIsImtleSI6InZhbGlkS2V5IiwiZWRpdHMiOnsiZ3JheXNjYWxlIjp0cnVlfSwib3V0cHV0Rm9ybWF0IjoianBlZyJ9' } process.env = { SOURCE_BUCKETS : "validBucket, validBucket2" @@ -45,6 +45,7 @@ describe('setup()', function() { bucket: 'validBucket', key: 'validKey', edits: { grayscale: true }, + outputFormat: 'jpeg', originalImage: Buffer.from('SampleImageContent\n') } // Assert @@ -644,4 +645,4 @@ describe('getAllowedSourceBuckets()', function() { }); }); }); -}) \ No newline at end of file +}) From 2c16a719aeb3f4ff26c07c643f4e3a8f2728d90b Mon Sep 17 00:00:00 2001 From: Levi Wilson Date: Fri, 5 Jul 2019 15:51:41 -0400 Subject: [PATCH 2/4] add a package.sh to build the distributable package with docker rather than the host machine --- README.md | 10 ++++++++++ package.sh | 15 +++++++++++++++ 2 files changed, 25 insertions(+) create mode 100755 package.sh diff --git a/README.md b/README.md index 866be7ec8..eccff8511 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,16 @@ _Note:_ In the above example, the solution template will expect the source code https://s3.amazonaws.com/my-bucket-name/serverless-image-handler/my-version/serverless-image-handler.template ``` +### Docker +If you have docker installed, you can build the distributable as well as run the unit tests with the following command from the root of the repository: + +``` +docker run --rm -it \ + -v $PWD:/development \ + -w /development \ + amazonlinux:2018.03 ./package.sh $DIST_OUTPUT_BUCKET $TEMPLATE_OUTPUT_BUCKET $VERSION +``` + Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Amazon Software License (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at diff --git a/package.sh b/package.sh new file mode 100755 index 000000000..62b591d5e --- /dev/null +++ b/package.sh @@ -0,0 +1,15 @@ +#! /bin/bash +set -e + +# install prerequisites +yum install -y gcc-c++ make which zip +curl -sL https://rpm.nodesource.com/setup_8.x | bash - +yum install -y nodejs + +cd deployment + +# tests +./run-unit-tests.sh + +# build output package +./build-s3-dist.sh $@ From d28215911e0a70b2a848a5fd45eab2a75b4e4722 Mon Sep 17 00:00:00 2001 From: Levi Wilson Date: Fri, 5 Jul 2019 15:56:17 -0400 Subject: [PATCH 3/4] accidental { in the .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e035d2539..db9cb9d4c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ # System Files **/.DS_Store -deployment/{dist +deployment/dist deployment/manifest-generator From c0ab6dbcac36697b358ff698ad9badc3b96e99e0 Mon Sep 17 00:00:00 2001 From: Levi Wilson Date: Fri, 5 Jul 2019 16:05:39 -0400 Subject: [PATCH 4/4] remove accidental start of fenced codeblockf for the clone command on the README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index eccff8511..d9161c334 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,6 @@ export VERSION=my-version # version number for the customized code ``` _Note:_ You would have to create 2 buckets, one named 'my-bucket-name' and another regional bucket named 'my-bucket-name-'; aws_region is where you are testing the customized solution. Also, the assets in bucket should be publicly accessible. -``` * Clone the github repo ```bash git clone https://github.com/awslabs/serverless-image-handler.git