Skip to content

Commit

Permalink
fix: update api bug
Browse files Browse the repository at this point in the history
  • Loading branch information
gideonsenku committed Jul 22, 2024
1 parent f431d7d commit 6a25023
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
11 changes: 5 additions & 6 deletions box/chavy.boxjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -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]]
}
Expand Down
7 changes: 7 additions & 0 deletions box/release/box.release.json
Original file line number Diff line number Diff line change
@@ -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"],
Expand Down
11 changes: 5 additions & 6 deletions chavy.box.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -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]]
}
Expand Down

0 comments on commit 6a25023

Please sign in to comment.