From cba0bf708f3d257e0c43a992bd0f19f6eea418ac Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Wed, 15 Apr 2020 22:01:55 +0200 Subject: [PATCH] luci-base: luci.js: convert various probe* functions to session data api Signed-off-by: Jo-Philipp Wich (cherry picked from commit b0c822192628f3346721810212b0770cc16ff6ea) --- .../htdocs/luci-static/resources/luci.js | 58 +++---------------- 1 file changed, 9 insertions(+), 49 deletions(-) diff --git a/modules/luci-base/htdocs/luci-static/resources/luci.js b/modules/luci-base/htdocs/luci-static/resources/luci.js index 77f1d8fa1..20c112e77 100644 --- a/modules/luci-base/htdocs/luci-static/resources/luci.js +++ b/modules/luci-base/htdocs/luci-static/resources/luci.js @@ -2520,12 +2520,8 @@ /* DOM setup */ probeRPCBaseURL: function() { - if (rpcBaseURL == null) { - try { - rpcBaseURL = window.sessionStorage.getItem('rpcBaseURL'); - } - catch (e) { } - } + if (rpcBaseURL == null) + rpcBaseURL = Session.getLocalData('rpcBaseURL'); if (rpcBaseURL == null) { var rpcFallbackURL = this.url('admin/ubus'); @@ -2535,11 +2531,7 @@ }, function() { return (rpcBaseURL = rpcFallbackURL); }).then(function(url) { - try { - window.sessionStorage.setItem('rpcBaseURL', url); - } - catch (e) { } - + Session.setLocalData('rpcBaseURL', url); return url; }); } @@ -2548,17 +2540,8 @@ }, probeSystemFeatures: function() { - var sessionid = classes.rpc.getSessionID(); - - if (sysFeatures == null) { - try { - var data = JSON.parse(window.sessionStorage.getItem('sysFeatures')); - - if (this.isObject(data) && this.isObject(data[sessionid])) - sysFeatures = data[sessionid]; - } - catch (e) {} - } + if (sysFeatures == null) + sysFeatures = Session.getLocalData('features'); if (!this.isObject(sysFeatures)) { sysFeatures = classes.rpc.declare({ @@ -2566,14 +2549,7 @@ method: 'getFeatures', expect: { '': {} } })().then(function(features) { - try { - var data = {}; - data[sessionid] = features; - - window.sessionStorage.setItem('sysFeatures', JSON.stringify(data)); - } - catch (e) {} - + Session.setLocalData('features', features); sysFeatures = features; return features; @@ -2584,17 +2560,8 @@ }, probePreloadClasses: function() { - var sessionid = classes.rpc.getSessionID(); - - if (preloadClasses == null) { - try { - var data = JSON.parse(window.sessionStorage.getItem('preloadClasses')); - - if (this.isObject(data) && this.isObject(data[sessionid])) - preloadClasses = data[sessionid]; - } - catch (e) {} - } + if (preloadClasses == null) + preloadClasses = Session.getLocalData('preload'); if (!Array.isArray(preloadClasses)) { preloadClasses = this.resolveDefault(classes.rpc.declare({ @@ -2615,14 +2582,7 @@ classes.push('preload.%s'.format(m[1])); } - try { - var data = {}; - data[sessionid] = classes; - - window.sessionStorage.setItem('preloadClasses', JSON.stringify(data)); - } - catch (e) {} - + Session.setLocalData('preload', classes); preloadClasses = classes; return classes; -- 2.25.1