From 1b64ce4b3b2ae896192426222b54149ee876c516 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Tue, 20 Nov 2018 14:33:27 -0500 Subject: [PATCH] Better token support in UI --- index.js | 2 +- public/js/main.js | 32 +++++++++++++------------------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/index.js b/index.js index e5e47c0..2f9aed6 100644 --- a/index.js +++ b/index.js @@ -160,7 +160,7 @@ app.post('/task/new', authCheck, addRequestId, upload.array('images'), (req, res }; if ((!req.files || req.files.length === 0) && !req.body.zipurl) die("Need at least 1 file or a zip file url."); - if (config.maxImages > 0 && req.files && req.files.length > config.maxImages) die(`${req.files.length} images uploaded, but this node can only process up to ${config.maxImages}.`); + else if (config.maxImages > 0 && req.files && req.files.length > config.maxImages) die(`${req.files.length} images uploaded, but this node can only process up to ${config.maxImages}.`); else { let destPath = path.join(Directories.data, req.id); diff --git a/public/js/main.js b/public/js/main.js index 4ff9c10..1864638 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -16,6 +16,14 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ $(function() { + function query(key) { + key = key.replace(/[*+?^$.\[\]{}()|\\\/]/g, "\\$&"); // escape RegEx meta chars + var match = location.search.match(new RegExp("[?&]"+key+"=([^&]+)(&|$)")); + return match && decodeURIComponent(match[1].replace(/\+/g, " ")); + } + + var token = query('token') || ""; + function hoursMinutesSecs(t) { var ch = 60 * 60 * 1000, cm = 60 * 1000, @@ -134,7 +142,7 @@ $(function() { } Task.prototype.refreshInfo = function() { var self = this; - var url = "/task/" + this.uuid + "/info"; + var url = "/task/" + this.uuid + "/info?token=" + token; $.get(url) .done(function(json) { // Track time @@ -160,7 +168,7 @@ $(function() { var self = this; function fetchOutput() { - var url = "/task/" + self.uuid + "/output"; + var url = "/task/" + self.uuid + "/output?token=" + token; $.get(url, { line: self.viewOutputLine }) .done(function(output) { for (var i in output) { @@ -269,7 +277,7 @@ $(function() { // Handle uploads $("#images").fileinput({ - uploadUrl: '/task/new', + uploadUrl: '/task/new?token=' + token, showPreview: false, allowedFileExtensions: ['jpg', 'jpeg', 'txt', 'zip'], elErrorContainer: '#errorBlock', @@ -299,18 +307,11 @@ $(function() { return; } - // Start upload - $("#images").fileinput('upload'); - - - + $("#images").fileinput('upload'); }); $('#resetWebhook').on('click', function(){ - - - $("#webhook").val(''); }); @@ -334,6 +335,7 @@ $(function() { $('#btnShowUpload').addClass('hidden'); $('#zipurl').val(''); }); + var btnUploadLabel = $("#btnUpload").val(); $("#images") @@ -359,14 +361,6 @@ $(function() { this.value(undefined); }; - function query(key) { - key = key.replace(/[*+?^$.\[\]{}()|\\\/]/g, "\\$&"); // escape RegEx meta chars - var match = location.search.match(new RegExp("[?&]"+key+"=([^&]+)(&|$)")); - return match && decodeURIComponent(match[1].replace(/\+/g, " ")); - } - - var token = query('token') || ""; - function OptionsModel() { var self = this;