Skip to content

Commit

Permalink
Node update, refactor, AVIF, animated images
Browse files Browse the repository at this point in the history
- updated node to the version `18`
- migrated from CommonJS to ESM
- changed directory structure
- small refactoring - private priperties and methods, removed unneccessary code etc.
- updated sharp and aws-sdk dependencies
- removed dependency `inversify`
- added eslint
- added support for AVIF
- added support for animated GIF and WebP
- changed background color to white when transparent image is converted to jpeg
- added Makefile
  • Loading branch information
tg666 committed Aug 16, 2023
1 parent 2d0ce5c commit 1898cfd
Show file tree
Hide file tree
Showing 67 changed files with 3,792 additions and 1,080 deletions.
126 changes: 8 additions & 118 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,135 +1,25 @@
# custom
# Build
.aws-sam
samconfig.toml
**/package-lock.json

# ====================

# Created by https://www.gitignore.io/api/osx,node,linux,windows

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Env
.env
*.env
.env.*

# Dependency directories
# Npm
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

### Linux ###
*~

### OSX ###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Windows ###
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk


# End of https://www.gitignore.io/api/osx,node,linux,windows
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
build:
sam build --use-container

deploy:
sam deploy

deploy.guided:
sam deploy --guided
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ But the application can be used standalone without `image-storage` of course.
## Requirements

- docker
- npm
- AWS SAM CLI

Please follow an official Amazon documentation if you don't have the AWS SAM CLI installed already:
Expand All @@ -19,8 +18,8 @@ Please follow an official Amazon documentation if you don't have the AWS SAM CLI
## Build and Deploy

```bash
$ sam build
$ sam deploy --guided
$ make build
$ make deploy.guided
```

## Application parameters
Expand Down Expand Up @@ -150,24 +149,25 @@ or example if you define `user::^userAvatar\/` and a path of a requested image w

#### Modifiers

| Name | Shortcut | Type | Note |
| --- | --- | --- | --- |
| Original | original | - | A modifier without a value, use it if you want to return the original image |
| Height | h | Integer | Can be restricted by parameter `AllowedResolutions` |
| Width | w | Integer | Can be restricted by parameter `AllowedResolutions` |
| Pixel density | pd | Integer\|Float | Can be restricted by parameter `AllowedPixelDensity` |
| Aspect ratio | ar | String | Required format is `{Int\|Float}x{Int\|Float}` and a height or a width (not both) must be also defined. For example `w:200,ar:1x2` is an equivalent of `w:200,h:400` |
| Fit | f | String | See [supported fits](#supported-fits) for the list of supported values |
| Orientation | o | Integer\|String | Allowed values are `auto, 0, 90, -90, 180, -180, 270, -270` |
| Quality | q | Integer | Can be restricted by parameter `AllowedQualities` |
| Name | Shortcut | Type | Note |
|---------------|----------|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Original | original | - | A modifier without a value, use it if you want to return the original image |
| Height | h | Integer | Can be restricted by parameter `AllowedResolutions` |
| Width | w | Integer | Can be restricted by parameter `AllowedResolutions` |
| Pixel density | pd | Integer\|Float | Can be restricted by parameter `AllowedPixelDensity` |
| Aspect ratio | ar | String | Required format is `{Int\|Float}x{Int\|Float}` and a height or a width (not both) must be also defined. For example `w:200,ar:1x2` is an equivalent of `w:200,h:400` |
| Fit | f | String | See [supported fits](#supported-fits) for the list of supported values |
| Orientation | o | Integer\|String | Allowed values are `auto, 0, 90, -90, 180, -180, 270, -270` |
| Quality | q | Integer | Can be restricted by parameter `AllowedQualities` |

#### Image types

- JPEG - `.jpeg` or `.jpg`
- Progressive JPEG - `.pjpg`
- PNG - `.png`
- GIF - `.gif`
- WEBP - `.webp`
- GIF - `.gif` (animations support)
- WEBP - `.webp` (animations support)
- AVIF - '.avif'

#### Supported fits

Expand All @@ -189,7 +189,7 @@ or example if you define `user::^userAvatar\/` and a path of a requested image w

Generated images are cached in a Cache Bucket. A name of the Cache Bucket that is defined by parameter `CacheBucketName`.
If some image is requested and the Cache Bucket contains it then the image is returned directly.
Otherwise a Lambda function is called and it will try to access the image through the Source Bucket (a name is defined by parameter `SourceBucketName`), modify it and save it to the Cache Bucket.
Otherwise, a Lambda function is called, and it will try to access the image through the Source Bucket (a name defined by parameter `SourceBucketName`), modify it and save it to the Cache Bucket.
The Lambda function can return an error 404 or a `no-image` image if some is provided by you.

#### What is the URL of my API?
Expand Down
19 changes: 19 additions & 0 deletions lambda/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"env": {
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"overrides": [],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
"indent": ["error", 4, { "SwitchCase": 1 }],
"comma-dangle": ["error", "always-multiline"],
"comma-spacing": ["error", { "before": false, "after": true }],
"no-trailing-spaces": "error",
"eol-last": ["error", "always"]
}
}
5 changes: 5 additions & 0 deletions lambda/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { application } from './src/bootstrap.mjs';

export const lambdaHandler = async event => {
return await application.run(event);
};
Loading

0 comments on commit 1898cfd

Please sign in to comment.