From: Rafał Miłecki <ra...@milecki.pl> This is proof of concept for the new uhttpd ubus API. It switches LuCI (in a bit hacky way) to the new API.
Signed-off-by: Rafał Miłecki <ra...@milecki.pl> --- .../htdocs/luci-static/resources/luci.js | 5 +++ .../htdocs/luci-static/resources/rpc.js | 31 +++++-------------- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/modules/luci-base/htdocs/luci-static/resources/luci.js b/modules/luci-base/htdocs/luci-static/resources/luci.js index e285f999e..9d2c52d77 100644 --- a/modules/luci-base/htdocs/luci-static/resources/luci.js +++ b/modules/luci-base/htdocs/luci-static/resources/luci.js @@ -739,11 +739,13 @@ if (!opt.cache) opt.url += ((/\?/).test(opt.url) ? '&' : '?') + (new Date()).getTime(); +/* if (isQueueableRequest(opt)) { requestQueue.push([opt, rejectFn, resolveFn]); requestAnimationFrame(flushRequestQueue); return; } +*/ if ('username' in opt && 'password' in opt) opt.xhr.open(opt.method, opt.url, true, opt.username, opt.password); @@ -758,6 +760,9 @@ if ('timeout' in opt) opt.xhr.timeout = +opt.timeout; + if ('authorization' in opt) + opt.xhr.setRequestHeader('Authorization', 'Bearer %s'.format(opt.authorization)); + if ('credentials' in opt) opt.xhr.withCredentials = !!opt.credentials; diff --git a/modules/luci-base/htdocs/luci-static/resources/rpc.js b/modules/luci-base/htdocs/luci-static/resources/rpc.js index 7bfc91336..5d9569d87 100644 --- a/modules/luci-base/htdocs/luci-static/resources/rpc.js +++ b/modules/luci-base/htdocs/luci-static/resources/rpc.js @@ -18,8 +18,8 @@ var rpcRequestID = 1, */ return baseclass.extend(/** @lends LuCI.rpc.prototype */ { /* privates */ - call: function(req, cb, nobatch) { - var q = ''; + call: function(object, req, cb) { + var q = 'call/%s'.format(object); if (Array.isArray(req)) { if (req.length == 0) @@ -33,13 +33,10 @@ return baseclass.extend(/** @lends LuCI.rpc.prototype */ { req[i].params[2] ); } - else if (req.params) { - q += '/%s.%s'.format(req.params[1], req.params[2]); - } return request.post(rpcBaseURL + q, req, { timeout: (L.env.rpctimeout || 20) * 1000, - nobatch: nobatch, + authorization: rpcSessionID, credentials: true }).then(cb, cb); }, @@ -89,16 +86,7 @@ return baseclass.extend(/** @lends LuCI.rpc.prototype */ { return req.reject(e); } - if (!req.object && !req.method) { - ret = msg.result; - } - else if (Array.isArray(msg.result)) { - if (req.raise && msg.result[0] !== 0) - L.raise('RPCError', 'RPC call to %s/%s failed with ubus code %d: %s', - req.object, req.method, msg.result[0], this.getStatusText(msg.result[0])); - - ret = (msg.result.length > 1) ? msg.result[1] : msg.result[0]; - } + ret = msg.result; if (req.expect) { for (var key in req.expect) { @@ -332,17 +320,12 @@ return baseclass.extend(/** @lends LuCI.rpc.prototype */ { var msg = { jsonrpc: '2.0', id: rpcRequestID++, - method: 'call', - params: [ - rpcSessionID, - options.object, - options.method, - params - ] + method: options.method, + params: params }; /* call rpc */ - rpc.call(msg, rpc.parseCallReply.bind(rpc, req), options.nobatch); + rpc.call(options.object, msg, rpc.parseCallReply.bind(rpc, req)); }); }, this, this, options); }, -- 2.27.0 _______________________________________________ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/mailman/listinfo/openwrt-devel