diff --git a/config.js b/config.js index 4170e81..770327c 100644 --- a/config.js +++ b/config.js @@ -37,6 +37,7 @@ Options: --test Enable test mode. In test mode, no commands are sent to OpenDroneMap. This can be useful during development or testing (default: false) --test_skip_orthophotos If test mode is enabled, skip orthophoto results when generating assets. (default: false) --test_skip_dems If test mode is enabled, skip dems results when generating assets. (default: false) + --test_drop_uploads If test mode is enabled, drop /task/new/upload requests with 50% probability. (default: false) --powercycle When set, the application exits immediately after powering up. Useful for testing launch and compilation issues. --token Sets a token that needs to be passed for every request. This can be used to limit access to the node only to token holders. (default: none) --max_images Specify the maximum number of images that this processing node supports. (default: unlimited) @@ -95,6 +96,7 @@ config.cleanupUploadsAfter = parseInt(argv.cleanup_uploads_after || fromConfigFi config.test = argv.test || fromConfigFile("test", false); config.testSkipOrthophotos = argv.test_skip_orthophotos || fromConfigFile("testSkipOrthophotos", false); config.testSkipDems = argv.test_skip_dems || fromConfigFile("testSkipDems", false); +config.testDropUploads = argv.test_drop_uploads || fromConfigFile("testDropUploads", false); config.powercycle = argv.powercycle || fromConfigFile("powercycle", false); config.token = argv.token || fromConfigFile("token", ""); config.maxImages = parseInt(argv.max_images || fromConfigFile("maxImages", "")) || null; diff --git a/index.js b/index.js index 3dc957c..0539ec1 100644 --- a/index.js +++ b/index.js @@ -144,7 +144,7 @@ app.post('/task/new/init', authCheck, taskNew.assignUUID, formDataParser, taskNe * schema: * $ref: '#/definitions/Error' */ -app.post('/task/new/upload/:uuid', authCheck, taskNew.getUUID, taskNew.uploadImages, taskNew.handleUpload); +app.post('/task/new/upload/:uuid', authCheck, taskNew.getUUID, taskNew.preUpload, taskNew.uploadImages, taskNew.handleUpload); /** @swagger * /task/new/commit/{uuid}: @@ -253,7 +253,6 @@ app.post('/task/new/commit/:uuid', authCheck, taskNew.getUUID, taskNew.handleCom * $ref: '#/definitions/Error' */ app.post('/task/new', authCheck, taskNew.assignUUID, taskNew.uploadImages, (req, res, next) => { - console.log(req.body); req.body = req.body || {}; if ((!req.files || req.files.length === 0) && !req.body.zipurl) req.error = "Need at least 1 file or a zip file url."; else if (config.maxImages && req.files && req.files.length > config.maxImages) req.error = `${req.files.length} images uploaded, but this node can only process up to ${config.maxImages}.`; @@ -813,7 +812,12 @@ process.on('SIGTERM', gracefulShutdown); process.on('SIGINT', gracefulShutdown); // Startup -if (config.test) logger.info("Running in test mode"); +if (config.test) { + logger.info("Running in test mode"); + if (config.testSkipOrthophotos) logger.info("Orthophotos will be skipped"); + if (config.testSkipDems) logger.info("DEMs will be skipped"); + if (config.testDropUploads) logger.info("Uploads will drop at random"); +} let commands = [ cb => odmInfo.initialize(cb), diff --git a/libs/taskNew.js b/libs/taskNew.js index 9620ba7..83ac25d 100644 --- a/libs/taskNew.js +++ b/libs/taskNew.js @@ -102,6 +102,17 @@ module.exports = { }); }, + preUpload: (req, res, next) => { + // Testing stuff + if (!config.test) next(); + else{ + if (config.testDropUploads){ + if (Math.random() < 0.5) res.sendStatus(500); + else next(); + } + } + }, + uploadImages: upload.array("images"), handleUpload: (req, res) => { @@ -140,13 +151,16 @@ module.exports = { else{ req.body = body; req.files = files; + + if (req.files.length === 0){ + req.error = "Need at least 1 file."; + } next(); } }); }, handleInit: (req, res) => { - console.log(req.body); req.body = req.body || {}; const srcPath = path.join("tmp", req.id); diff --git a/public/index.html b/public/index.html index cb1839f..2a212a9 100644 --- a/public/index.html +++ b/public/index.html @@ -14,8 +14,19 @@ padding-top: 50px; padding-bottom: 20px; } + .navbar{ + background-color: #3498db; + } + a:hover, a:focus, a:active, a{ + color: #3498db; + } + #images{ + font-weight: bold; + } + #btnSelectFiles, #images{ + display: inline-block; + } - @@ -29,34 +40,34 @@
-
-

New Task

-
-
-