Permalink
Browse files

add back remove functionality

  • Loading branch information...
madhums committed Aug 9, 2012
1 parent b09e70a commit 2c461ec675d75d586164f310a0ba61ca2733286b
Showing with 56 additions and 1 deletion.
  1. +56 −1 lib/imager.js
@@ -103,7 +103,7 @@ Imager.prototype.resizeFile = function (file, preset, fname, cb) {
, width: preset.size.split('x')[0]
}

im.resize(options, function(err, stdout, stderr){
im.resize(options, function(err, stdout, stderr) {
if (err) return cb(err)
self['pushTo' + self.storage](dest, remoteFile, filename, file['type'], cb)
})
@@ -169,10 +169,65 @@ Imager.prototype.pushToRackspace = function (file, remoteFile, filename, type, c
}


Imager.prototype.remove = function (files, callback, variant) {
var self = this

var prepareRemove = function (file, iteratorCallback) {
self.prepareRemove(file, iteratorCallback, variant)
}

async.forEach(files, prepareRemove, function (err) {
if (err) return callback(err)
callback(null)
})
}


Imager.prototype.prepareRemove = function (file, iteratorCallback, variant) {
var variants = this.config.variants[variant]
, asyncArr = []
, self = this

if (variants.resize) {
Object.keys(variants.resize).forEach(function (preset) {
var removeFiles = function (cb) {
self['removeFrom' + self.storage](file, preset, cb)
}

asyncArr.push(removeFiles)
})
}

if (variants.crop) {
Object.keys(variants.crop).forEach(function (preset) {
var removeFiles = function (cb) {
self['removeFrom' + self.storage](file, preset, cb)
}

asyncArr.push(removeFiles)
})
}

async.parallel(asyncArr, function (err, results) {
iteratorCallback(err)
})
}


Imager.prototype.removeFromRackspace = function (file, preset, cb) {
var self = this
, client = cloudfiles.createClient(this.config['storage'][this.storage])
, rsContainer = this.config['storage'][this.storage].container
, filename = preset + '_' + file

client.setAuth(function() {
client.getContainer(rsContainer, true, function (err, container) {
if (err) return callback(err)

container.removeFile(filename, function(err){
if (err) console.log(err)
cb(err)
})
})
})
}

0 comments on commit 2c461ec

Please sign in to comment.