diff --git a/lib/transport/local.js b/lib/transport/local.js index b15c300..85d8451 100644 --- a/lib/transport/local.js +++ b/lib/transport/local.js @@ -119,24 +119,33 @@ module.exports = function(opts) { }, delete: function(req, res, callback) { - var options = this.options; - var fileName = ''; - if (req.url.slice(0, options.uploadUrl.length) === options.uploadUrl) { - fileName = path.basename(decodeURIComponent(req.url)); - if (fileName[0] !== '.') { - fs.unlink(options.uploadDir + '/' + fileName, function(ex) { - Object.keys(options.imageVersions).forEach(function(version) { - // TODO - Missing callback - fs.unlink(options.uploadDir + '/' + version + '/' + fileName); - }); - callback(null, { - success: true - }); - }); - return; + var options = this.options; + var fileName = ''; + if (req.url.slice(0, options.uploadUrl.length) === options.uploadUrl) { + fileName = path.basename(decodeURIComponent(req.url)); + if (fileName[0] !== '.') { + fs.unlink(options.uploadDir + '/' + fileName, function (ex) { + // Done - Added error passing here + if (ex) { + callback({ error: ex, failure: true }, null); } + Object.keys(options.imageVersions).forEach(function (version) { + // Done - Added callback here + fs.unlink(options.uploadDir + '/' + version + '/' + fileName, function (ex) { + //Done - Added error passing here + if (ex) { + callback({ error: ex, failure: true }, null); + } + }); + }); + callback(null, { + success: true + }); + }); + return; } - callback(new Error('File name invalid:' + fileName), null); + } + callback(new Error('File name invalid:' + fileName), null); } };