luci-base: luci.js: convert various probe* functions to session data api
authorJo-Philipp Wich <jo@mein.io>
Wed, 15 Apr 2020 20:01:55 +0000 (22:01 +0200)
committerJo-Philipp Wich <jo@mein.io>
Thu, 7 May 2020 17:40:49 +0000 (19:40 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(cherry picked from commit b0c822192628f3346721810212b0770cc16ff6ea)

modules/luci-base/htdocs/luci-static/resources/luci.js

index 77f1d8fa18284432f820e4be6c791fc3116e008b..20c112e7784f462c94d22bf8e4e1b46716c77783 100644 (file)
 
                /* 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');
                                }, function() {
                                        return (rpcBaseURL = rpcFallbackURL);
                                }).then(function(url) {
-                                       try {
-                                               window.sessionStorage.setItem('rpcBaseURL', url);
-                                       }
-                                       catch (e) { }
-
+                                       Session.setLocalData('rpcBaseURL', url);
                                        return url;
                                });
                        }
                },
 
                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({
                                        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;
                },
 
                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({
                                                        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;