From: Paul Donald Date: Thu, 8 Jan 2026 17:12:40 +0000 (+0100) Subject: luci-base: amend rpc to handle objects in param X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=fddc70391f7ea2b36713ca67b37111e2746f6bd9;p=openwrt-luci.git luci-base: amend rpc to handle objects in param This allows more complex and nested call constructions. Example: const container_create = rpc.declare({ object: 'frob', method: 'glob', params: { foo: { }, bar: { } }, }); Signed-off-by: Paul Donald --- diff --git a/modules/luci-base/htdocs/luci-static/resources/rpc.js b/modules/luci-base/htdocs/luci-static/resources/rpc.js index 903d9d0b60..9213b2cd5f 100644 --- a/modules/luci-base/htdocs/luci-static/resources/rpc.js +++ b/modules/luci-base/htdocs/luci-static/resources/rpc.js @@ -299,9 +299,20 @@ return baseclass.extend(/** @lends LuCI.rpc.prototype */ { /* build parameter object */ let p_off = 0; const params = { }; - if (Array.isArray(options.params)) + if (Array.isArray(options.params)) { + // Array style: parameter names are positional for (p_off = 0; p_off < options.params.length; p_off++) params[options.params[p_off]] = args[p_off]; + } else if (typeof(options.params) === 'object') { + // Object style: first arg is an object with the parameter keys + const argObj = args[0]; + if (argObj && typeof(argObj) === 'object') { + for (let key in options.params) + if (key in argObj) + params[key] = argObj[key]; + } + p_off = 1; + } /* all remaining arguments are private args */ const priv = [ undefined, undefined ];