Download of assets

pull/1/head
Piero Toffanin 2016-07-18 16:00:01 -05:00
rodzic f157aba2d8
commit 23bdfe3103
4 zmienionych plików z 28 dodań i 5 usunięć

Wyświetl plik

@ -86,6 +86,15 @@ app.get('/task/:uuid/info', getTaskFromUuid, (req, res) => {
app.get('/task/:uuid/output', getTaskFromUuid, (req, res) => {
res.json(req.task.getOutput(req.query.line));
});
app.get('/task/:uuid/download/:asset', getTaskFromUuid, (req, res) => {
if (!req.params.asset || req.params.asset === "all"){
res.download(req.task.getAssetsArchivePath(), "all.zip", err => {
if (err) res.json({error: "Asset not ready"});
});
}else{
res.json({error: "Invalid asset"});
}
});
let uuidCheck = (req, res, next) => {
if (!req.body.uuid) res.json({error: "uuid param missing."});

Wyświetl plik

@ -62,6 +62,12 @@ module.exports = class Task{
return `data/${this.uuid}`;
}
// Get the path of the archive where all assets
// outputted by this task are stored.
getAssetsArchivePath(){
return `${this.getProjectFolderPath()}/all.zip`;
}
// Deletes files and folders related to this task
cleanup(cb){
rmdir(this.getProjectFolderPath(), cb);
@ -138,12 +144,10 @@ module.exports = class Task{
zip.addLocalFolder(`${this.getProjectFolderPath()}/odm_georeferencing`);
zip.addLocalFolder(`${this.getProjectFolderPath()}/odm_texturing`);
zip.addLocalFolder(`${this.getProjectFolderPath()}/odm_meshing`);
zip.writeZip(`${this.getProjectFolderPath()/all.zip}`);
zip.writeZip(this.getAssetsArchivePath());
this.setStatus(statusCodes.COMPLETED);
finished();
// TODO: test, think about possibly doing this on the fly
// upon download request...
}
function finished(){

Wyświetl plik

@ -71,6 +71,10 @@
<span data-bind="css: 'statusIcon glyphicon ' + icon()"></span>
<div class="actionButtons">
<button data-bind="click: download, visible: showDownload()" type="button" class="btn btn-primary btn-sm" >
<span class="glyphicon glyphicon-download-alt"></span> Download Results
</button>
<button data-bind="click: cancel, visible: showCancel()" type="button" class="btn btn-primary btn-sm" >
<span class="glyphicon glyphicon-remove-circle"></span> Cancel
</button>

Wyświetl plik

@ -109,7 +109,10 @@ $(function(){
return this.info().status &&
(this.info().status.code === codes.FAILED || this.info().status.code === codes.COMPLETED || this.info().status.code === codes.CANCELED);
}, this);
this.showDownload = ko.pureComputed(function(){
return this.info().status &&
(this.info().status.code === codes.COMPLETED);
}, this);
this.startRefreshingInfo();
}
Task.prototype.refreshInfo = function(){
@ -229,6 +232,9 @@ $(function(){
Task.prototype.restart = genApiCall("/task/restart", function(task){
task.resetOutput();
});
Task.prototype.download = function(){
location.href = "/task/" + this.uuid + "/download/all";
};
var taskList = new TaskList();
ko.applyBindings(taskList);