From ee7f84d2b6b856d2e3aecfae0de92081af1274aa Mon Sep 17 00:00:00 2001 From: Simon Grim Date: Tue, 22 Mar 2016 17:43:04 +0500 Subject: [PATCH] add and fix checks for daemon version and input data for short URI related functions --- js/interface_common.js | 14 ++++++++++---- js/twister_actions.js | 4 ++++ js/twister_io.js | 6 ++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/js/interface_common.js b/js/interface_common.js index de8222f..10fd56a 100644 --- a/js/interface_common.js +++ b/js/interface_common.js @@ -808,7 +808,17 @@ function openRequestShortURIForm() { //txtTitle: polyglot.t(''), add some title (not 'error', please) or just KISS txtMessage: 'You can\'t short links because you are not logged in.' }); + return; } + if (parseInt(twisterVersion) < 93500) { + alertPopup({ + //txtTitle: polyglot.t(''), add some title (not 'error', please) or just KISS + txtMessage: 'You can\'t short links because twister daemon is obsolete!\n' + + 'Version 0.9.35 or higher is required. Please keep your twister up to date.' + }); + return; + } + var uri = prompt('enter a link, watch yourself carefully'); // FIXME newShortURI(uri, function (req, uriLong, uriShort) { @@ -852,10 +862,6 @@ function fetchShortenedURI(req) { applyShortenedURI(req, twister.URIs[req]); return; } - if (parseInt(twisterVersion) < 93500) { - console.warn('can\'t fetch URI "' + req + '": daemon is obsolete, version 0.9.35 or higher is required'); - return; - } decodeShortURI(req, function (req, ret) { diff --git a/js/twister_actions.js b/js/twister_actions.js index 4f178ca..a245089 100644 --- a/js/twister_actions.js +++ b/js/twister_actions.js @@ -324,6 +324,10 @@ function newRtMsg(postData, msg) { function newShortURI(uri, cbFunc, cbReq) { if (!uri || !defaultScreenName) return; + if (parseInt(twisterVersion) < 93500) { + console.warn('can\'t short URI "' + uri + '": daemon is obsolete, version 0.9.35 or higher is required'); + return; + } for (var i in twister.URIs) if (twister.URIs[i] === uri) { diff --git a/js/twister_io.js b/js/twister_io.js index c19b7c5..3de9e4c 100644 --- a/js/twister_io.js +++ b/js/twister_io.js @@ -113,6 +113,12 @@ function dhtget(peerAlias, resource, multi, cbFunc, cbReq, timeoutArgs) { // the expanded url is returned to callback // null is passed to callback in case of an error function decodeShortURI(locator, cbFunc, cbReq, timeoutArgs) { + if (!locator) return; + if (parseInt(twisterVersion) < 93500) { + console.warn('can\'t fetch URI "' + req + '": daemon is obsolete, version 0.9.35 or higher is required'); + return; + } + if (_dhtgetPendingMap[locator]) { _dhtgetAddPending(locator, cbFunc, cbReq); } else {