Added set-uuid parameter in headers for /task/new

pull/56/head
Piero Toffanin 2018-12-02 14:44:37 -05:00
rodzic e4e6054aca
commit 2b76079bbd
6 zmienionych plików z 59 dodań i 49 usunięć

Wyświetl plik

@ -8,7 +8,7 @@ REST API to access ODM
=== Version information
[%hardbreaks]
_Version_ : 1.2.1
_Version_ : 1.2.2
=== Contact information
@ -167,16 +167,18 @@ Creates a new task and places it at the end of the processing queue
[options="header", cols=".^2,.^3,.^9,.^4,.^2"]
|===
|Type|Name|Description|Schema|Default
|*Header*|*set-uuid* +
_optional_|An optional UUID string that will be used as UUID for this task instead of generating a random one.|string|
|*Query*|*token* +
_optional_|Token required for authentication (when authentication is required).|string|
|*FormData*|*images* +
_optional_|Images to process, plus an optional GPC file. If included, the GPC file should have .txt extension|file|
_optional_|Images to process, plus an optional GCP file. If included, the GCP file should have .txt extension|file|
|*FormData*|*name* +
_optional_|An optional name to be associated with the task|string|
|*FormData*|*options* +
_optional_|Serialized JSON string of the options to use for processing, as an array of the format: [{name: option1, value: value1}, {name: option2, value: value2}, …]. For example, [{"name":"cmvs-maxImages","value":"500"},{"name":"time","value":true}]. For a list of all options, call /options|string|
|*FormData*|*zipurl* +
_optional_|URL of the zip file containing the images to process, plus an optional GPC file. If included, the GPC file should have .txt extension|string|
_optional_|URL of the zip file containing the images to process, plus an optional GCP file. If included, the GCP file should have .txt extension|string|
|===

File diff suppressed because one or more lines are too long

Wyświetl plik

@ -17,35 +17,36 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
"use strict";
let fs = require('fs');
let config = require('./config.js');
let packageJson = JSON.parse(fs.readFileSync('./package.json'));
const fs = require('fs');
const config = require('./config.js');
const packageJson = JSON.parse(fs.readFileSync('./package.json'));
let logger = require('./libs/logger');
let path = require('path');
let async = require('async');
let mime = require('mime');
let rmdir = require('rimraf');
const logger = require('./libs/logger');
const path = require('path');
const async = require('async');
const mime = require('mime');
const rmdir = require('rimraf');
let express = require('express');
let app = express();
const express = require('express');
const app = express();
let addRequestId = require('./libs/expressRequestId')();
let multer = require('multer');
let bodyParser = require('body-parser');
let morgan = require('morgan');
const multer = require('multer');
const bodyParser = require('body-parser');
const morgan = require('morgan');
let TaskManager = require('./libs/TaskManager');
let Task = require('./libs/Task');
let odmInfo = require('./libs/odmInfo');
let Directories = require('./libs/Directories');
let unzip = require('node-unzip-2');
let si = require('systeminformation');
let mv = require('mv');
let S3 = require('./libs/S3');
const TaskManager = require('./libs/TaskManager');
const Task = require('./libs/Task');
const odmInfo = require('./libs/odmInfo');
const Directories = require('./libs/Directories');
const unzip = require('node-unzip-2');
const si = require('systeminformation');
const mv = require('mv');
const S3 = require('./libs/S3');
let auth = require('./libs/auth/factory').fromConfig(config);
const auth = require('./libs/auth/factory').fromConfig(config);
const authCheck = auth.getMiddleware();
const uuidv4 = require('uuid/v4');
// zip files
let request = require('request');
@ -106,13 +107,13 @@ let server;
* -
* name: images
* in: formData
* description: Images to process, plus an optional GPC file. If included, the GPC file should have .txt extension
* description: Images to process, plus an optional GCP file. If included, the GCP file should have .txt extension
* required: false
* type: file
* -
* name: zipurl
* in: formData
* description: URL of the zip file containing the images to process, plus an optional GPC file. If included, the GPC file should have .txt extension
* description: URL of the zip file containing the images to process, plus an optional GCP file. If included, the GCP file should have .txt extension
* required: false
* type: string
* -
@ -133,6 +134,12 @@ let server;
* description: 'Token required for authentication (when authentication is required).'
* required: false
* type: string
* -
* name: set-uuid
* in: header
* description: 'An optional UUID string that will be used as UUID for this task instead of generating a random one.'
* required: false
* type: string
* responses:
* 200:
* description: Success
@ -148,7 +155,24 @@ let server;
* schema:
* $ref: '#/definitions/Error'
*/
app.post('/task/new', authCheck, addRequestId, upload.array('images'), (req, res) => {
app.post('/task/new', authCheck, (req, res, next) => {
// A user can optionally suggest a UUID instead of letting
// nodeODM pick one.
if (req.get('set-uuid')){
const userUuid = req.get('set-uuid');
// Valid UUID and no other task with same UUID?
if (/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(userUuid) && !taskManager.find(userUuid)){
req.id = userUuid;
next();
}else{
res.json({error: `Invalid set-uuid: ${userUuid}`})
}
}else{
req.id = uuidv4();
next();
}
}, upload.array('images'), (req, res) => {
let srcPath = path.join("tmp", req.id);
// Print error message and cleanup

Wyświetl plik

@ -1,17 +0,0 @@
'use strict';
let uuid = require('node-uuid');
module.exports = function (options) {
options = options || {};
options.uuidVersion = options.uuidVersion || 'v4';
options.setHeader = options.setHeader === undefined || !!options.setHeader;
return function (req, res, next) {
req.id = uuid[options.uuidVersion](options, options.buffer, options.offset);
if (options.setHeader) {
res.setHeader('X-Request-Id', req.id);
}
next();
};
};

Wyświetl plik

@ -1,6 +1,6 @@
{
"name": "node-opendronemap",
"version": "1.2.1",
"version": "1.2.2",
"description": "REST API to access ODM",
"main": "index.js",
"scripts": {
@ -33,12 +33,12 @@
"mv": "^2.1.1",
"node-schedule": "^1.1.1",
"node-unzip-2": "^0.2.7",
"node-uuid": "^1.4.7",
"request": "^2.88.0",
"rimraf": "^2.5.3",
"swagger-jsdoc": "^1.3.1",
"systeminformation": "^3.42.0",
"tree-kill": "^1.1.0",
"uuid": "^3.3.2",
"winston": "^2.2.0"
},
"devDependencies": {

Wyświetl plik

@ -286,6 +286,7 @@ $(function() {
elErrorContainer: '#errorBlock',
showUpload: false,
uploadAsync: false,
// ajaxSettings: { headers: { 'set-uuid': '8366b2ad-a608-4cd1-bdcb-c3d84a034623' } },
uploadExtraData: function() {
return {
name: $("#taskName").val(),