Permalink
Browse files

v0.1.0

  • Loading branch information...
1 parent 476043e commit 50cc3b0a7afaba13d04da4d5ef366967f8464443 @tih-ra committed Dec 25, 2011
Showing with 30 additions and 18 deletions.
  1. +29 −17 lib/alleup.js
  2. +1 −1 package.json
View
@@ -9,13 +9,13 @@ var config_file = './alleup.json',
config = {},
s3client = undefined,
uploaddir = undefined,
- storage_type = undefined;
+ storage_type = undefined,
+ scope = undefined;
var Alleup = exports = module.exports = function Alleup(options) {
config_file = (typeof options['config_file'] === 'undefined') ? config_file : options['config_file'];
storage_type = options['storage'];
-
this.loadConfig(config_file);
if ( typeof (config['storage']['aws'] || config['storage']['dir']) == 'undefined' )
@@ -38,7 +38,7 @@ Alleup.prototype = {
},
dirUrl: function(file) {
- return uploaddir + file;
+ return '/' + uploaddir + file;
},
awsUrl: function(file) {
@@ -50,9 +50,12 @@ Alleup.prototype = {
return version + '_' + file;
},
- remove: function(file, callback) {
- var _resize = config['variants']['resize'];
- var _crop = config['variants']['crop'];
+ remove: function(file, callback, _scope) {
+ scope = (arguments.length == 3) ? _scope : undefined
+ var _variants = this.setupVariants()
+
+ var _resize = _variants['resize'];
+ var _crop = _variants['crop'];
for(version in _resize) {
eval('this.' + storage_type + 'Remove')( this.genFileName( file, version ), function(err) {
@@ -81,8 +84,10 @@ Alleup.prototype = {
},
- upload: function(req, res, callback) {
- var _this = this;
+ upload: function(req, res, callback, _scope) {
+ scope = (arguments.length == 4) ? _scope : undefined
+
+ var _this = this;
var form = new formidable.IncomingForm(),
files = [],
fields = [],
@@ -131,9 +136,11 @@ Alleup.prototype = {
makeVariants: function(file, callback) {
var _this = this;
+ var _variants = this.setupVariants()
+
+ var _resize = _variants["resize"] || JSON.parse( JSON.stringify({"null" : "null"}) );
+ var _crop = _variants["crop"] || JSON.parse( JSON.stringify({"null" : "null"}) );
- var _resize = config['variants']['resize'];
- var _crop = config['variants']['crop'];
var new_file = Math.round(new Date().getTime());
var ext = this.setExtension(file['type']);
new_file += ext;
@@ -143,13 +150,12 @@ Alleup.prototype = {
this.imAction('im.resize', file, this.genFileName( new_file, prefix ) , _resize[prefix], function(err){
i++;
- if (i == Object.keys(config.variants.resize).length ) {
+ if (i == Object.keys(_resize).length ) {
i = 0;
for(prefix in _crop) {
-
_this.imAction('im.crop', file, _this.genFileName( new_file, prefix ) , _crop[prefix], function(err){
i++;
- if (i == Object.keys(config.variants.crop).length ) {
+ if (i == Object.keys(_crop).length ) {
fs.unlink(file['path']);
callback(err, new_file);
};
@@ -162,6 +168,12 @@ Alleup.prototype = {
};
},
+
+ setupVariants: function() {
+ var resize = (typeof scope === 'undefined') ? config.variants.resize : eval('config.variants.'+scope+'.resize')
+ var crop = (typeof scope === 'undefined') ? config.variants.crop : eval('config.variants.'+scope+'.crop')
+ return { "resize" : resize, "crop" : crop }
+ },
pushToS3: function(sfile, dfile, content_type, callback) {
@@ -192,6 +204,9 @@ Alleup.prototype = {
},
imAction: function(action, file, prefix, size, callback) {
+ if (size == "null") {
+ return callback(null);
+ }
var _this = this;
@@ -240,8 +255,5 @@ Alleup.prototype = {
quality: 1
};
}
-
-
-
-};
+};
View
@@ -2,7 +2,7 @@
"author": "Andriy Bazuta <andriy.bazyuta@gmail.com> (http://andriy.bazyuta.me)",
"name": "alleup",
"description": "Flexible way to resize and upload images to Amazon S3 or file system storages",
- "version": "0.0.5",
+ "version": "0.1.0",
"keywords": ["upload", "image", "imagemagick", "amazon", "aws", "s3", "resize", "file"],
"homepage": "https://github.com/tih-ra/alleup",
"repository": {

0 comments on commit 50cc3b0

Please sign in to comment.