Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(release): Update im-metadata to v3.0.0 #55

Closed
wants to merge 48 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
ab0b415
Refactor format handling for AWS S3 version upload
Jun 12, 2015
da59994
Bump im-resize dependency to ~2.1
Jun 12, 2015
16c6079
Tag release v1.0.0-rc.3
Jun 12, 2015
0317bc6
Add missing format parameter
anthonyringoet Jun 12, 2015
5a2cd61
Bump im-resize dependency to ~2.2
Jun 23, 2015
7a8c0b1
Tag release v1.0.0-rc.4
Jun 23, 2015
9d933da
Add a link to the old v0.x docs from README
Starefossen Jun 24, 2015
1d2787c
Configure Wercker CI builds with Docker
Jun 25, 2015
05731e1
Document minimum ImageMagick version required
Jun 25, 2015
30bc322
Use lastest major version of dev dependencies
Jun 25, 2015
adf9d6e
Specify supported engine versions
Jun 25, 2015
df94eab
Add CoffeLint to dev dependencies
Jun 25, 2015
2317e36
CoffeeLint: Trim all lines to max 80 chars
Jun 25, 2015
7b0d353
Rename `awsBucketName` to `bucketName`
Jun 25, 2015
9827c2b
Upgade io.js version for local test environment
Jun 25, 2015
f1971c0
Bump im-metadata dependency to ~2.2
Jun 25, 2015
d8141f6
Auto rotate image dimensions metadata
Jun 25, 2015
9d2c5af
Add some special version variations to test setup
Jun 25, 2015
fcc6623
Update package metadata tags
Jun 25, 2015
64ae339
Tag release v1.0.0-rc.5
Jun 25, 2015
3216713
Update NPM ignore list
Jun 26, 2015
764f179
Clean up Wercker CI build configuration
Jun 26, 2015
4189a63
Update environment variables for dev environment
Jun 26, 2015
758aae6
Update build and pre-publish commands
Jun 26, 2015
a0efc73
Update test and test-watch commands
Jun 26, 2015
012edcf
Remove full binary path for run scripts
Jun 26, 2015
bdceae9
Tag release v1.0.0-rc.10
Jun 26, 2015
08f7bf7
Bump im-resize dependency to ~2.3
Jul 28, 2015
b3ffe50
Attach width and height to original image version
Jul 28, 2015
3e9fefe
Add awsImageAcl to all processed image versions
Jul 28, 2015
6b1305f
Sync suite test configuration with README.md
Jul 28, 2015
b37f396
Bump async dependency to ~1.4
Jul 28, 2015
54e2c05
Tag release v1.0.0-rc.11
Jul 28, 2015
56e0ffc
Clean up upload example in README.md
Jul 29, 2015
16df74c
Update stable/0.x documentation warning message
Jul 29, 2015
2475752
Tag release v1.0.0
Jul 29, 2015
05b5329
Add image upload overview figure to README
Aug 21, 2015
1c854c2
fixing typo - privat to private
lfreneda Sep 17, 2015
02397c9
Fix typo in default acl param
codemanki Sep 22, 2015
3eebc0b
Tag release v1.0.1
Sep 22, 2015
ffb6329
feat(aws): support image cache control headers
Sep 22, 2015
6c20395
feat(path): add support for custom random paths
Sep 5, 2015
73e608e
Tag release v2.1.0-rc.1
Oct 13, 2015
59b5eea
revert: this reverts commit 8d75e47
Oct 14, 2015
1434f8c
Tag release v1.1.0-rc.1
Oct 14, 2015
1967b74
deps(aws): upgrade aws-sdk to ^2.2.9
Oct 13, 2015
60c6b78
feat(path): set absolute path for uploaded image
Oct 14, 2015
63ef256
Tag release v1.1.0-rc.2
Oct 14, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ results

node_modules/
test_output/
.vagrant/
env/
src/
test/
utils/

Vagrantfile
docker-compose.yml
wercker.yml

.vim.custom
.gitignore
.npmignore
.DS_Store
Expand Down
40 changes: 25 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
AWS S3 Image Uploader
=====================

**Documentation for `[email protected]` can be found [here](https://github.com/Turistforeningen/node-s3-uploader/blob/stable/0.x/README.md).**

[![Build status](https://img.shields.io/wercker/ci/54f18246d9b14636634ff908.svg "Build status")](https://app.wercker.com/project/bykey/50fbdf51cf64b01a738379a028b8a885)
[![NPM downloads](https://img.shields.io/npm/dm/s3-uploader.svg "NPM downloads")](https://www.npmjs.com/package/s3-uploader)
[![NPM version](https://img.shields.io/npm/v/s3-uploader.svg "NPM version")](https://www.npmjs.com/package/s3-uploader)
Expand All @@ -13,6 +15,8 @@ and [im-resize](https://github.com/Turistforeningen/node-im-resize) and
[im-metadata](https://github.com/Turistforeningen/node-im-metadata) for image
processing.

![Overview of image upload to AWS S3](https://docs.google.com/drawings/d/1EZaE8LaQ6FRSg4R-2QQiT1af-y2AgDknBGrx6SPIKy0/pub?w=766&h=216)

[![Join the chat at https://gitter.im/Turistforeningen/node-s3-uploader](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Turistforeningen/node-s3-uploader)

## Changelog
Expand All @@ -29,7 +33,7 @@ npm install s3-uploader --save
## Requirements

* Node.JS >= v0.10
* imagemagic
* ImageMagic >= v6.8
* AWS credentials environment variables
* `AWS_ACCESS_KEY_ID`
* `AWS_SECRET_ACCESS_KEY`
Expand All @@ -55,7 +59,7 @@ var Upload = require('s3-uploader');
* **object** `aws` - see [note](#aws-note)
* **string** `region` - region for you bucket (**default** `us-east-1`)
* **string** `path` - path within your bucket (**default** `""`)
* **string** `acl` - default ACL for uploaded images (**default** `privat`)
* **string** `acl` - default ACL for uploaded images (**default** `private`)
* **string** `accessKeyId` - AWS access key ID override
* **string** `secretAccessKey` - AWS secret access key override

Expand All @@ -67,15 +71,22 @@ var Upload = require('s3-uploader');
* **object[]** `versions`
* **string** `suffix` - image file name suffix (**default** `""`)
* **number** `quality` - image resize quality
* **string** `format` - force output image file format (**default** `format of original image`)
* **number** `maxWidth` - max width for resized image
* **number** `maxHeight` - max height for resized image
* **string** `aspect` - force aspect ratio for resized image (**example:** `4:3`
* **string** `background` - set background for transparent images (**example:** `red`)
* **boolean** `flatten` - flatten backgrund for transparent images
* **string** `awsImageAcl` - access control for AWS S3 upload (**example:** `private`)
* **number** `awsImageExpires` - add `Expires` header to image version
* **number** `awsImageCacheControl` - add `Cache-Control` header to image version

* **object** `original`
* **string** `awsImageAcl` - access control for AWS S3 upload (**example:** `private`)
* **number** `awsImageExpires` - add `Expires` header to image version
* **number** `awsImageCacheControl` - add `Cache-Control` header to image version

* **function** `randomPath` - custom random path function

#### AWS note
> The `aws` object is passed directly to `aws-sdk`. You can add any of [these
Expand Down Expand Up @@ -104,22 +115,21 @@ var client = new Upload('my_s3_bucket', {
versions: [{
maxHeight: 1040,
maxWidth: 1040,
format: 'jpg',
suffix: '-large',
quality: 80
},{
maxHeight: 780,
maxWidth: 780,
aspect: '4:3',
aspect: '3:2!h',
suffix: '-medium'
},{
maxHeight: 320,
maxWidth: 320,
aspect: '4:3',
aspect: '16:9!h',
suffix: '-small'
},{
maxHeight: 100,
maxWidth: 100,
aspect: '1:1',
format: 'png',
suffix: '-thumb1'
},{
maxHeight: 250,
Expand All @@ -136,6 +146,7 @@ var client = new Upload('my_s3_bucket', {

* **object** `opts`
* **string** `awsPath` - override the path on AWS set through `opts.aws.path`
* **string** `path` - set absolute path for uploaded image (disables random path)

* **function** `cb` - callback function (**Error** `err`, **object[]** `versions`, **object** `meta`)
* **Error** `err` - `null` if everything went fine
Expand All @@ -145,14 +156,13 @@ var client = new Upload('my_s3_bucket', {
#### Example

```javascript
client.upload('/some/file/path.jpg', {}, function(err, images, meta) {
if (err) {
console.error(err);
} else {
for (var i = 0; i < images.length; i++) {
console.log('Thumbnail with width %i, height %i, at %s', images[i].width, images[i].height, images[i].url);
}
}
client.upload('/some/image.jpg', {}, function(err, versions, meta) {
if (err) { throw err; }

versions.forEach(function(image) {
console.log(image.width, image.height, image.url);
// 1234 4567 https://my-bucket.s3.amazonaws.com/path/ab/cd/ef.jpg
});
});
```

Expand Down
7 changes: 5 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
dev:
image: starefossen/iojs-imagemagick:1-6
image: starefossen/iojs-imagemagick:2-6
working_dir: /usr/src/app
volumes:
- ".:/usr/src/app"
command: "npm run watch"
env_file: .env
environment:
NODE_ENV: development
- NODE_ENV=development
- NPM_CONFIG_LOGLEVEL=info
- NPM_PACKAGE_CONFIG_UNSAFE_PERM=true
- NPM_CONFIG_UNSAFE_PERM=true
32 changes: 19 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"name": "s3-uploader",
"version": "1.0.0-rc.2",
"version": "1.1.0-rc.2",
"description": "Resize, rename, and upload images to AWS S3",
"main": "lib/index.js",
"directories": {
"test": "test"
},
"scripts": {
"build": "coffee --bare --compile --output lib/ src/*.coffee",
"prepublish": "coffee --bare --compile --output lib/ src/*.coffee",
"build": "coffee -c -b -o lib/ src/*.coffee",
"prepublish": "coffee -c -b -o lib/ src/*.coffee",
"postpublish": "rm -rf lib/*",
"test": "mocha test/suite.coffee -R spec --compilers coffee:coffee-script/register,litcoffee:coffee-script/register",
"watch": "./node_modules/.bin/mocha -w -b -c --check-leaks test/suite.coffee -R progress --compilers coffee:coffee-script/register,litcoffee:coffee-script/register"
"hint": "coffeelint src test",
"test": "mocha --compilers coffee:coffee-script/register test/suite.coffee",
"watch": "mocha -w -b -c --check-leaks -R progress --compilers coffee:coffee-script/register test/suite.coffee"
},
"repository": {
"type": "git",
Expand All @@ -24,7 +25,8 @@
"image",
"resize",
"rename",
"upload"
"upload",
"versions"
],
"contributors": [
"Håvard Ranum <[email protected]>",
Expand All @@ -36,16 +38,20 @@
},
"homepage": "https://github.com/Turistforeningen/node-s3-uploader",
"devDependencies": {
"coffee-script": "~1.9.1",
"mocha": "~2.2.1"
"coffee-script": "~1",
"coffeelint": "~1",
"mocha": "~2",
"uuid": "^2"
},
"dependencies": {
"async": "~1.2",
"aws-sdk": "~2.1",
"im-resize": "~2.0",
"im-metadata": "~2.1"
"@starefossen/rand-path": "^1.0.1",
"async": "~1.4",
"aws-sdk": "^2.2.9",
"im-metadata": "~2.2",
"im-resize": "~2.3"
},
"engines": {
"node": ">=0.10"
"node": ">=0.10",
"iojs": ">=1.0.0"
}
}
65 changes: 34 additions & 31 deletions src/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ retry = require('async').retry
resize = require 'im-resize'
metadata = require 'im-metadata'

Upload = module.exports = (awsBucketName, @opts = {}) ->
throw new TypeError 'Bucket name can not be undefined' if not awsBucketName
Upload = module.exports = (bucketName, @opts = {}) ->
throw new TypeError 'Bucket name can not be undefined' if not bucketName

@opts.aws ?= {}
#@opts.aws.accessKeyId
@opts.aws.acl ?= 'privat'
@opts.aws.acl ?= 'private'
@opts.aws.httpOptions ?= {}
@opts.aws.httpOptions.timeout ?= 10000
@opts.aws.maxRetries ?= 3
@opts.aws.params ?= {}
@opts.aws.params.Bucket = awsBucketName
@opts.aws.params.Bucket = bucketName
@opts.aws.path ?= ''
@opts.aws.region ?= 'us-east-1'
#@opts.aws.secretAccessKey
Expand All @@ -37,28 +37,16 @@ Upload = module.exports = (awsBucketName, @opts = {}) ->
@opts.versions ?= []

if not @opts.url and @opts.aws.region is 'us-east-1'
@opts.url ?= "https://s3.amazonaws.com/#{@opts.aws.params.Bucket}/"
@opts.url ?= "https://s3.amazonaws.com/#{bucketName}/"
else if not @opts.url
@opts.url ?= "https://s3-#{@opts.aws.region}.amazonaws.com/#{@opts.aws.params.Bucket}/"
@opts.url ?= "https://s3-#{@opts.aws.region}.amazonaws.com/#{bucketName}/"

@._getRandomPath = @opts.randomPath or require('@starefossen/rand-path')

@s3 = new S3 @opts.aws

@

##
# Generate a random path on the form /xx/yy/zz
##
Upload.prototype._getRandomPath = ->
input = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
res = []

for i in [1..3]
x = input[Math.floor((Math.random() * input.length))]
y = input[Math.floor((Math.random() * input.length))]
res.push x + y

return res.join '/'

##
# Generate a random avaiable path on the S3 bucket
##
Expand Down Expand Up @@ -98,13 +86,18 @@ Image.prototype.start = (cb) ->
# Get image metadata
##
Image.prototype.getMetadata = (src, cb) ->
metadata src, exif: @upload.opts.returnExif, cb
metadata src, exif: @upload.opts.returnExif, autoOrient: true, cb

##
# Get image destination
##
Image.prototype.getDest = (cb) ->
prefix = @opts?.awsPath or @upload.opts.aws.path

if @opts.path
return process.nextTick =>
cb null, prefix + @opts.path

@upload._getDestPath prefix, cb

##
Expand All @@ -123,10 +116,13 @@ Image.prototype.resizeVersions = (cb, results) ->
##
Image.prototype.uploadVersions = (cb, results) ->
if @upload.opts.original
results.versions.push
awsImageAcl: @upload.opts.original.awsImageAcl
original: true
path: @src
org = JSON.parse(JSON.stringify(@upload.opts.original))
org.original = true
org.width = results.metadata.width
org.height = results.metadata.height
org.path = @src

results.versions.push org

map results.versions, @_upload.bind(@, results.dest), cb

Expand All @@ -136,8 +132,8 @@ Image.prototype.uploadVersions = (cb, results) ->
Image.prototype.removeVersions = (cb, results) ->
each results.uploads, (image, callback) =>
if not @upload.opts.cleanup.original and image.original \
or not @upload.opts.cleanup.versions and not image.original
return setTimeout callback, 0
or not @upload.opts.cleanup.versions and not image.original
return setTimeout callback, 0

fs.unlink image.path, callback
, (err) ->
Expand All @@ -147,13 +143,20 @@ Image.prototype.removeVersions = (cb, results) ->
# Upload image version to S3
##
Image.prototype._upload = (dest, version, cb) ->
format = extname version.path
version.awsImageAcl ?= @upload.opts.aws.acl
format = extname(version.path).substr(1).toLowerCase()

options =
Key: dest + (version.suffix || '') + format
ACL: version.awsImageAcl or @upload.opts.aws.acl
Key: "#{dest}#{version.suffix or ''}.#{format}"
ACL: version.awsImageAcl
Body: fs.createReadStream version.path
ContentType: "image/#{if format is '.jpg' then 'jpeg' else format.substr(1)}"
ContentType: "image/#{if format is 'jpg' then 'jpeg' else format}"

if version.awsImageExpires
options.Expires = new Date(Date.now() + version.awsImageExpires)

if version.awsImageMaxAge
options.CacheControl = "public, max-age=#{version.awsImageMaxAge}"

@upload.s3.putObject options, (err, data) =>
return cb err if err
Expand Down
Loading