diff --git a/box/chavy.boxjs.js b/box/chavy.boxjs.js index a230c533f..38e88b20e 100644 --- a/box/chavy.boxjs.js +++ b/box/chavy.boxjs.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.19.8' +$.version = '0.19.9' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -711,20 +711,19 @@ async function apiSave() { async function apiUpdate() { const data = $.toObj($request.body) - const path = data.path + const path = data.path.split('.') const val = data.val - const key = path.split('.')[0] + const key = path.shift() switch (key) { case 'usercfgs': const usercfgs = getUserCfgs() - update(usercfgs, path, val) + update(usercfgs, path.join('.'), val) $.setjson(usercfgs, $.KEY_usercfgs) break default: break } - $.json = getBoxData() } @@ -960,7 +959,7 @@ function update(obj, path, value) { for (let i = 0; i < keys.length - 1; i++) { if (!current[keys[i]]) { - current[keys[i]] = null + current[keys[i]] = {} } current = current[keys[i]] } diff --git a/box/release/box.release.json b/box/release/box.release.json index 2645f7eeb..fb0c54f6c 100644 --- a/box/release/box.release.json +++ b/box/release/box.release.json @@ -1,5 +1,12 @@ { "releases": [ + { + "version": "0.19.9", + "tags": ["beta"], + "author": "@GideonSenku", + "msg": "fix(boxjs): 修复 /api/update 进行局部数据更新", + "notes": [] + }, { "version": "0.19.8", "tags": ["beta"], diff --git a/chavy.box.js b/chavy.box.js index a230c533f..38e88b20e 100644 --- a/chavy.box.js +++ b/chavy.box.js @@ -3,7 +3,7 @@ const $ = new Env('BoxJs') // 为 eval 准备的上下文环境 const $eval_env = {} -$.version = '0.19.8' +$.version = '0.19.9' $.versionType = 'beta' // 发出的请求需要需要 Surge、QuanX 的 rewrite @@ -711,20 +711,19 @@ async function apiSave() { async function apiUpdate() { const data = $.toObj($request.body) - const path = data.path + const path = data.path.split('.') const val = data.val - const key = path.split('.')[0] + const key = path.shift() switch (key) { case 'usercfgs': const usercfgs = getUserCfgs() - update(usercfgs, path, val) + update(usercfgs, path.join('.'), val) $.setjson(usercfgs, $.KEY_usercfgs) break default: break } - $.json = getBoxData() } @@ -960,7 +959,7 @@ function update(obj, path, value) { for (let i = 0; i < keys.length - 1; i++) { if (!current[keys[i]]) { - current[keys[i]] = null + current[keys[i]] = {} } current = current[keys[i]] }