Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sagidM/s3-resizer
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: nelsonamaya82/s3-resizer
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on Jan 30, 2020

  1. Copy the full SHA
    a4fa587 View commit details
  2. Copy the full SHA
    afc1bd7 View commit details
  3. Fix typo

    nelsonamaya82 committed Jan 30, 2020
    Copy the full SHA
    0e3fb0f View commit details
Showing with 20 additions and 3 deletions.
  1. +3 −1 .gitignore
  2. +2 −1 README.md
  3. +15 −1 index.js
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/node_modules
/node_modules
.DS_Store
*.zip
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -138,9 +138,10 @@ or
* * **Function code -> Code entry type -> Upload a .zip file** upload a zip file
* * In **Runtime**, select the latest version of Node.js that you found on [Releases](https://github.com/sagidM/s3-resizer/releases)
* * [You can now click on **Save** to save your time because it takes a while to upload a zip file]
* * Set up these two **Environment variables** _(format: key=value)_
* * Set up these three **Environment variables** _(format: key=value)_
**BUCKET**=_your bucket's name_
**URL**=**Endpoint** you copied before (from Static website hosting)
**WHITELIST**= your list (space-separated) of allowed size options (e.g. AUTOx150 300x200 100x100_max)
* * In **Basic settings**
* * * Allocate 768mb memory
* * * Timeout could be 5 seconds
16 changes: 15 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -7,20 +7,34 @@ const Sharp = require('sharp');
const PathPattern = /(.*\/)?(.*)\/(.*)/;

// parameters
const {BUCKET, URL} = process.env;
const {BUCKET, URL, WHITELIST} = process.env;


exports.handler = async (event) => {
const path = event.queryStringParameters.path;
const parts = PathPattern.exec(path);
const dir = parts[1] || '';
const sizeOption = parts[2];
const options = parts[2].split('_');
const filename = parts[3];


const sizes = options[0].split("x");
const action = options.length > 1 ? options[1] : null;

// Whitelist validation.
if (WHITELIST) {
const whitelistArr = WHITELIST.split(' ');
if (!whitelistArr.includes(sizeOption)) {
return {
statusCode: 400,
body: `Unknown size parameter "${sizeOption}"`,
headers: {"Content-Type": "text/plain"}
};
}
}

// Action validation.
if (action && action !== 'max' && action !== 'min') {
return {
statusCode: 400,