From fddc70391f7ea2b36713ca67b37111e2746f6bd9 Mon Sep 17 00:00:00 2001 From: Paul Donald Date: Thu, 8 Jan 2026 18:12:40 +0100 Subject: [PATCH] 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 --- .../luci-base/htdocs/luci-static/resources/rpc.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 ]; -- 2.30.2