{ [Error: ENOENT, no such file or directory './config/s3.json'] errno: 34, code: 'ENOENT', path: './config/s3.json', syscall: 'open' } { [Error: ENOENT, no such file or directory './config/s3.json'] errno: 34, code: 'ENOENT', path: './config/s3.json', syscall: 'open' } { [Error: ENOENT, no such file or directory './config/s3.json'] errno: 34, code: 'ENOENT', path: './config/s3.json', syscall: 'open' } { [Error: ENOENT, no such file or directory './config/s3.json'] errno: 34, code: 'ENOENT', path: './config/s3.json', syscall: 'open' } { [Error: ENOENT, no such file or directory './config/s3.json'] errno: 34, code: 'ENOENT', path: './config/s3.json', syscall: 'open' } { [Error: ENOENT, no such file or directory './config/s3.json'] errno: 34, code: 'ENOENT', path: './config/s3.json', syscall: 'open' } sample.txt sample.txt { [CredentialsError: Missing credentials in config] message: 'Missing credentials in config', code: 'CredentialsError', errno: 'Unknown system errno 64', syscall: 'connect', time: Sun Mar 15 2015 01:14:34 GMT+0100 (CET), originalError: { message: 'Could not load credentials from any providers', code: 'CredentialsError', errno: 'Unknown system errno 64', syscall: 'connect', time: Sun Mar 15 2015 01:14:34 GMT+0100 (CET), originalError: { code: 'Unknown system errno 64', errno: 'Unknown system errno 64', syscall: 'connect', message: 'connect Unknown system errno 64' } } } Successfully uploaded the file images/output/sample-thumb.png Successfully uploaded the file images/output/sample-carousel.png Successfully uploaded the file images/output/sample-big.png Successfully uploaded the file images/output/sample-S.png Successfully uploaded the file images/output/sample-M.png Successfully uploaded the file images/output/sample-L.png Successfully uploaded the file images/output/sample.png Successfully uploaded the file images/output/sample-verybig.png Successfully uploaded the file images/output/sample-carousel.jpg Successfully uploaded the file images/output/sample-thumb.jpg Successfully uploaded the file images/output/sample-big.jpg Successfully uploaded the file images/output/sample-S.jpg Successfully uploaded the file images/output/sample-M.jpg Successfully uploaded the file images/output/sample-L.jpg Successfully uploaded the file images/output/sample-verybig.jpg Successfully uploaded the file images/output/sample.jpg Coverage

Coverage

95%
74
71
3

lib/processor.coffee

100%
14
14
0
LineHitsSource
11_ = require 'lodash/object'
21im = require 'imagemagick-native'
3
41module.exports = class Processor
51 constructor: (@config)->
618 defaultConf =
7 quality: 70
8 resizeStyle: 'aspectfill'
9 gravity: 'Center'
1018 @config = _.assign defaultConf, @getSize(), @config
11
12 process: (data)->
1314 @config.srcData = data
1414 @fixQualityForPNG()
1514 im.convert @config
16
17 getSize: ()->
1819 s = @config.size.split 'x'
1919 width: s[0], height: s[1]
20
21 fixQualityForPNG: () ->
2214 if @config.format == "PNG"
237 @config.quality = 100 - @config.quality
247 @config.quality = 1 unless @config.quality > 0
25

lib/store.coffee

92%
25
23
2
LineHitsSource
11AWS = require 'aws-sdk'
21fse = require 'fs-extra'
3
4###*
5 * StoreS3
6 * Store file in Amazon S3
7###
81module.exports.StoreS3 = class StoreS3
91 constructor: (@config)->
1012 try
1112 AWS.config.loadFromPath(@config.s3Path or './config/s3.json')
12 catch err
136 console.log err
1412 @s3 = new AWS.S3()
15
16 prepare: (__newFile)->
173 params =
18 Bucket: @config.bucket
19 Key: __newFile.filename
20 Body: __newFile.Body
21 ContentLength: __newFile.byteCount
22 ACL:'public-read'
23
24 process: (__newFile, done)->
252 filename = __newFile.filename
262 console.log filename
272 @s3.putObject @prepare(__newFile), (err, data)->
281 if err
291 console.log err
30 else
310 console.log 'Successfully uploaded the file', filename
321 done() if done
33
34###*
35 * StoreLocale
36 * store file in locale folder
37###
381module.exports.StoreLocale = class StoreLocale
391 constructor: (@config)->
40
41 prepare: (__newFile)->
4216 __newFile.Body
43
44 process: (__newFile, done)->
4516 filename = __newFile.filename
4616 fse.outputFile filename, @prepare(__newFile), (err)->
4716 if err
480 console.log err
49 else
5016 console.log 'Successfully uploaded the file', filename
5116 done() if done
52

lib/thumber.coffee

97%
35
34
1
LineHitsSource
11_ = require 'lodash/object'
21fse = require 'fs-extra'
31{StoreS3, StoreLocale} = require './store'
41Processor = require './processor'
5
61module.exports = class Thumber
71 constructor: (config) ->
83 defaultConf =
9 directory: 'upload/'
10 quality: 70
11 ifOriginal: true
123 @config = _.assign {}, defaultConf, config
133 @schemas = @config.schemas or [{version: 'thumb', size: '50x50'}]
143 if @config.store == 's3'
151 @store = new StoreS3 @config
162 else if @config.store == 'locale'
172 @store = new StoreLocale @config
18 else
190 console.warn "Upload not working: You need a config.store"
20
21 process: (path, filename, size, done) ->
222 fse.readFile path, (err, data) =>
23 # console.log err, data
242 return done(err) if err
252 base64data = new Buffer data, 'binary'
262 file =
27 'filename': @fullname filename
28 'Body': base64data
29 'byteCount': size
30 # write
312 @thumber data, filename
322 if @config.ifOriginal then @write(file, done) else done()
33
34 thumber: (data, filename) ->
352 @schemas.forEach (sc) =>
3614 sc = @prepare(sc, filename)
3714 processor = new Processor sc
3814 sc.Body = processor.process data
3914 @write sc
40
41 fullname: (filename, version) ->
4219 extension = filename.split(".")
4319 @config.extension = extension[extension.length - 1]
4419 @config.format = @config.extension.toUpperCase()
4519 ext = ".#{@config.extension}"
4619 fname = if version then filename.replace(ext,'-'+version+ext) else filename
4719 @config.directory + fname
48
49 prepare: (sc, filename) ->
5014 scConf = _.assign {}, @config, sc, {filename: @fullname(filename, sc.version)}
5114 delete scConf.schemas if scConf.schemas?
5214 scConf
53
54 write: (__newFile, done)->
5516 @store.process(__newFile, done) if @store
56
57
58