diff --git a/libs/taskNew.js b/libs/taskNew.js index 3714e54..9692d54 100644 --- a/libs/taskNew.js +++ b/libs/taskNew.js @@ -163,7 +163,7 @@ module.exports = { else cb(null, body); }); }catch(e){ - cb("Malformed body.json"); + cb(new Error("Malformed body.json")); } } }); @@ -244,10 +244,14 @@ module.exports = { let destGcpPath = path.join(destPath, "gcp"); const checkMaxImageLimits = (cb) => { - fs.readdir(destImagesPath, (err, files) => { - if (config.maxImages && files.length > config.maxImages) cb(`${files.length} images uploaded, but this node can only process up to ${config.maxImages}.`); - else cb(err); - }); + if (!config.maxImages) cb(); + else{ + fs.readdir(destImagesPath, (err, files) => { + if (err) cb(err); + else if (files.length > config.maxImages) cb(new Error(`${files.length} images uploaded, but this node can only process up to ${config.maxImages}.`)); + else cb(); + }); + } }; async.series([ @@ -319,11 +323,6 @@ module.exports = { ziputils.unzip(seedFileDst, destPath, cb); }, - // Verify max images limit - cb => { - checkMaxImageLimits(cb); - }, - // Remove cb => { fs.exists(seedFileDst, exists => { @@ -335,20 +334,10 @@ module.exports = { } const handleZipUrl = (cb) => { - async.series([ - // Extract images - cb => { - ziputils.unzip(path.join(destImagesPath, "zipurl.zip"), - destImagesPath, - cb, - true); - }, - - // Count files - cb => { - checkMaxImageLimits(cb); - } - ], cb); + // Extract images + ziputils.unzip(path.join(destImagesPath, "zipurl.zip"), + destImagesPath, + cb, true); } // Find and handle zip files and extract @@ -366,6 +355,11 @@ module.exports = { }); }, + // Verify max images limit + cb => { + checkMaxImageLimits(cb); + }, + cb => { // Find any *.txt (GCP) file and move it to the data//gcp directory // also remove any lingering zipurl.zip