Feature: Allow Zip File uploads

Feature: Optional webhook callback option
pull/8/head
Lee Pepper 2017-04-11 21:55:52 -06:00
rodzic 3ed48cffbb
commit fbca4187be
5 zmienionych plików z 83 dodań i 16 usunięć

Wyświetl plik

@ -181,16 +181,17 @@ app.post('/task/new', addRequestId, upload.array('images'), (req, res) => {
if (err) cb(err);
else{
// unzip and flatten the zip file (in case there are folders in the zip)
fs.createReadStream(archiveDestPath).pipe(unzip.Parse())
.on('entry', function(entry) {
if (entry.type === 'File') {
entry.pipe(fs.createWriteStream(path.join(srcPath, path.basename(entry.path))));
} else {
entry.autodrain();
}
})
.on('close', cb)
.on('error', cb);
// fs.createReadStream(archiveDestPath).pipe(unzip.Parse())
// .on('entry', function(entry) {
// if (entry.type === 'File') {
// entry.pipe(fs.createWriteStream(path.join(srcPath, path.basename(entry.path))));
// } else {
// entry.autodrain();
// }
// })
// .on('close', cb)
// .on('error', cb);
cb();
}
});
}
@ -204,6 +205,34 @@ app.post('/task/new', addRequestId, upload.array('images'), (req, res) => {
cb => fs.mkdir(destGpcPath, undefined, cb),
cb => fs.rename(srcPath, destImagesPath, cb),
cb => {
// Find any *.zip file and extract
fs.readdir(destImagesPath, (err, entries) => {
if (err) cb(err);
else {
async.eachSeries(entries, (entry, cb) => {
if (/\.zip$/gi.test(entry)) {
fs.createReadStream(path.join(destImagesPath, entry)).pipe(unzip.Parse())
.on('entry', function(entry) {
if (entry.type === 'File') {
entry.pipe(fs.createWriteStream(path.join(destImagesPath, path.basename(entry.path))));
} else {
entry.autodrain();
}
})
.on('close', cb)
.on('error', cb);
} else cb();
}, cb);
}
});
},
cb => {
// Find any *.txt (GPC) file and move it to the data/<uuid>/gpc directory
// also remove any lingering zipurl.zip
@ -213,7 +242,7 @@ app.post('/task/new', addRequestId, upload.array('images'), (req, res) => {
async.eachSeries(entries, (entry, cb) => {
if (/\.txt$/gi.test(entry)) {
fs.rename(path.join(destImagesPath, entry), path.join(destGpcPath, entry), cb);
}else if (entry === 'zipurl.zip'){
}else if (/\.zip$/gi.test(entry)){
fs.unlink(path.join(destImagesPath, entry), cb);
} else cb();
}, cb);
@ -230,7 +259,7 @@ app.post('/task/new', addRequestId, upload.array('images'), (req, res) => {
res.json({ uuid: req.id });
cb();
}
}, req.body.options);
}, req.body.options, req.body.webhook);
}
], err => {
if (err) res.json({ error: err.message });

Wyświetl plik

@ -34,7 +34,7 @@ let Directories = require('./Directories');
let statusCodes = require('./statusCodes');
module.exports = class Task{
constructor(uuid, name, done, options = []){
constructor(uuid, name, done, options = [], webhook){
assert(uuid !== undefined, "uuid must be set");
assert(done !== undefined, "ready must be set");
@ -47,6 +47,8 @@ module.exports = class Task{
this.gpcFiles = [];
this.output = [];
this.runningProcesses = [];
this.webhook = webhook;
async.series([
// Read images info

Wyświetl plik

@ -27,6 +27,10 @@ let statusCodes = require('./statusCodes');
let async = require('async');
let schedule = require('node-schedule');
let Directories = require('./Directories');
let request = require('request');
const TASKS_DUMP_FILE = path.join(Directories.data, "tasks.json");
const CLEANUP_TASKS_IF_OLDER_THAN = 1000 * 60 * 60 * 24 * config.cleanupTasksAfter; // days
@ -149,6 +153,19 @@ module.exports = class TaskManager{
if (task){
this.addToRunningQueue(task);
task.start(() => {
if(task.webhook && task.webhook.length > 3){
request({
uri: task.webhook,
method: 'POST',
json: task.getInfo()
},
function (error, response, body) {
if (!error && response.statusCode == 200) {
}
});
}
this.removeFromRunningQueue(task);
this.processNextTask();
});

Wyświetl plik

@ -46,11 +46,11 @@
<label for="taskName">Project Name:</lable> <input type="text" class="form-control" value="" id="taskName" />
</div>
<div id="imagesInput" class="form-group">
<label for="images">Aerial Images and GCP List (optional):</label> <input id="images" name="images" multiple type="file">
<label for="images">Aerial Images and GCP List (optional):</label> <input id="images" name="images" multiple accept="image/*|.txt|.zip" type="file">
</div>
<div id="zipFileInput" class="form-group hidden">
<label for="zipurl">URL to zip file with Aerial Images and GCP List (optional):</label> <input id="zipurl" name="zipurl" class="form-control" multiple type="text">
<label for="zipurl">URL to zip file with Aerial Images and GCP List (optional):</label> <input id="zipurl" name="zipurl" class="form-control" type="text">
<div id="errorBlock" class="help-block"></div>
</div>
@ -64,6 +64,17 @@
<button style="position: relative; top: -45px;" type="submit" class="btn btn-default" data-bind="visible: !error(), click: function(){ showOptions(!showOptions()); }, text: (showOptions() ? 'Hide' : 'Show') + ' Options'"></button>
<div data-bind="visible: showOptions()">
<div >
<label for="webhook">webhook callback url (optional):</label>
<br/>
<input id="webhook" name="webhook" class="form-control" type="text">
<button type="submit" class="btn glyphicon glyphicon-info-sign btn-info" data-toggle="tooltip" data-placement="top" title="Optional webhook" ></button>
<button id="resetWebhook" type="submit" class="btn glyphicon glyphicon glyphicon-repeat btn-default" data-toggle="tooltip" data-placement="top" title="Reset to default" ></button>
<br/><br/>
</div>
<div data-bind="foreach: options">
<label data-bind="text: properties.name + (properties.domain ? ' (' + properties.domain + ')' : '')"></label><br/>
<!-- ko if: properties.type !== 'bool' -->

Wyświetl plik

@ -271,7 +271,7 @@ $(function() {
$("#images").fileinput({
uploadUrl: '/task/new',
showPreview: false,
allowedFileExtensions: ['jpg', 'jpeg', 'txt'],
allowedFileExtensions: ['jpg', 'jpeg', 'txt', 'zip'],
elErrorContainer: '#errorBlock',
showUpload: false,
uploadAsync: false,
@ -279,6 +279,7 @@ $(function() {
return {
name: $("#taskName").val(),
zipurl: $("#zipurl").val(),
webhook: $("#webhook").val(),
options: JSON.stringify(optionsModel.getUserOptions())
};
}
@ -292,6 +293,13 @@ $(function() {
$("#images").fileinput('upload');
});
$('#resetWebhook').on('click', function(){
$("#webhook").val('');
});
// zip file control
$('#btnShowImport').on('click', function(e){
e.preventDefault();