{ [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
| Line | Hits | Source |
|---|---|---|
| 1 | 1 | _ = require 'lodash/object' |
| 2 | 1 | im = require 'imagemagick-native' |
| 3 | ||
| 4 | 1 | module.exports = class Processor |
| 5 | 1 | constructor: (@config)-> |
| 6 | 18 | defaultConf = |
| 7 | quality: 70 | |
| 8 | resizeStyle: 'aspectfill' | |
| 9 | gravity: 'Center' | |
| 10 | 18 | @config = _.assign defaultConf, @getSize(), @config |
| 11 | ||
| 12 | process: (data)-> | |
| 13 | 14 | @config.srcData = data |
| 14 | 14 | @fixQualityForPNG() |
| 15 | 14 | im.convert @config |
| 16 | ||
| 17 | getSize: ()-> | |
| 18 | 19 | s = @config.size.split 'x' |
| 19 | 19 | width: s[0], height: s[1] |
| 20 | ||
| 21 | fixQualityForPNG: () -> | |
| 22 | 14 | if @config.format == "PNG" |
| 23 | 7 | @config.quality = 100 - @config.quality |
| 24 | 7 | @config.quality = 1 unless @config.quality > 0 |
| 25 |
| Line | Hits | Source |
|---|---|---|
| 1 | 1 | AWS = require 'aws-sdk' |
| 2 | 1 | fse = require 'fs-extra' |
| 3 | ||
| 4 | ###* | |
| 5 | * StoreS3 | |
| 6 | * Store file in Amazon S3 | |
| 7 | ### | |
| 8 | 1 | module.exports.StoreS3 = class StoreS3 |
| 9 | 1 | constructor: (@config)-> |
| 10 | 12 | try |
| 11 | 12 | AWS.config.loadFromPath(@config.s3Path or './config/s3.json') |
| 12 | catch err | |
| 13 | 6 | console.log err |
| 14 | 12 | @s3 = new AWS.S3() |
| 15 | ||
| 16 | prepare: (__newFile)-> | |
| 17 | 3 | 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)-> | |
| 25 | 2 | filename = __newFile.filename |
| 26 | 2 | console.log filename |
| 27 | 2 | @s3.putObject @prepare(__newFile), (err, data)-> |
| 28 | 1 | if err |
| 29 | 1 | console.log err |
| 30 | else | |
| 31 | 0 | console.log 'Successfully uploaded the file', filename |
| 32 | 1 | done() if done |
| 33 | ||
| 34 | ###* | |
| 35 | * StoreLocale | |
| 36 | * store file in locale folder | |
| 37 | ### | |
| 38 | 1 | module.exports.StoreLocale = class StoreLocale |
| 39 | 1 | constructor: (@config)-> |
| 40 | ||
| 41 | prepare: (__newFile)-> | |
| 42 | 16 | __newFile.Body |
| 43 | ||
| 44 | process: (__newFile, done)-> | |
| 45 | 16 | filename = __newFile.filename |
| 46 | 16 | fse.outputFile filename, @prepare(__newFile), (err)-> |
| 47 | 16 | if err |
| 48 | 0 | console.log err |
| 49 | else | |
| 50 | 16 | console.log 'Successfully uploaded the file', filename |
| 51 | 16 | done() if done |
| 52 |
| Line | Hits | Source |
|---|---|---|
| 1 | 1 | _ = require 'lodash/object' |
| 2 | 1 | fse = require 'fs-extra' |
| 3 | 1 | {StoreS3, StoreLocale} = require './store' |
| 4 | 1 | Processor = require './processor' |
| 5 | ||
| 6 | 1 | module.exports = class Thumber |
| 7 | 1 | constructor: (config) -> |
| 8 | 3 | defaultConf = |
| 9 | directory: 'upload/' | |
| 10 | quality: 70 | |
| 11 | ifOriginal: true | |
| 12 | 3 | @config = _.assign {}, defaultConf, config |
| 13 | 3 | @schemas = @config.schemas or [{version: 'thumb', size: '50x50'}] |
| 14 | 3 | if @config.store == 's3' |
| 15 | 1 | @store = new StoreS3 @config |
| 16 | 2 | else if @config.store == 'locale' |
| 17 | 2 | @store = new StoreLocale @config |
| 18 | else | |
| 19 | 0 | console.warn "Upload not working: You need a config.store" |
| 20 | ||
| 21 | process: (path, filename, size, done) -> | |
| 22 | 2 | fse.readFile path, (err, data) => |
| 23 | # console.log err, data | |
| 24 | 2 | return done(err) if err |
| 25 | 2 | base64data = new Buffer data, 'binary' |
| 26 | 2 | file = |
| 27 | 'filename': @fullname filename | |
| 28 | 'Body': base64data | |
| 29 | 'byteCount': size | |
| 30 | # write | |
| 31 | 2 | @thumber data, filename |
| 32 | 2 | if @config.ifOriginal then @write(file, done) else done() |
| 33 | ||
| 34 | thumber: (data, filename) -> | |
| 35 | 2 | @schemas.forEach (sc) => |
| 36 | 14 | sc = @prepare(sc, filename) |
| 37 | 14 | processor = new Processor sc |
| 38 | 14 | sc.Body = processor.process data |
| 39 | 14 | @write sc |
| 40 | ||
| 41 | fullname: (filename, version) -> | |
| 42 | 19 | extension = filename.split(".") |
| 43 | 19 | @config.extension = extension[extension.length - 1] |
| 44 | 19 | @config.format = @config.extension.toUpperCase() |
| 45 | 19 | ext = ".#{@config.extension}" |
| 46 | 19 | fname = if version then filename.replace(ext,'-'+version+ext) else filename |
| 47 | 19 | @config.directory + fname |
| 48 | ||
| 49 | prepare: (sc, filename) -> | |
| 50 | 14 | scConf = _.assign {}, @config, sc, {filename: @fullname(filename, sc.version)} |
| 51 | 14 | delete scConf.schemas if scConf.schemas? |
| 52 | 14 | scConf |
| 53 | ||
| 54 | write: (__newFile, done)-> | |
| 55 | 16 | @store.process(__newFile, done) if @store |
| 56 | ||
| 57 | ||
| 58 |