Skip to content

Commit

Permalink
feat(boxjs): 新增 /api/deleteAppSub 删除订阅
Browse files Browse the repository at this point in the history
  • Loading branch information
gideonsenku committed Aug 13, 2024
1 parent 84d579e commit 8596c26
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 50 deletions.
56 changes: 31 additions & 25 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.10'
$.version = '0.19.11'
$.versionType = 'beta'

// 发出的请求需要需要 Surge、QuanX 的 rewrite
Expand Down Expand Up @@ -277,30 +277,27 @@ async function handleQuery() {
async function handleApi() {
const [, api] = $.path.split('/api')

if (api === '/save' || api.startsWith('/save?')) {
await apiSave()
} else if (api === '/addAppSub') {
await apiAddAppSub()
} else if (api === '/reloadAppSub') {
await apiReloadAppSub()
} else if (api === '/delGlobalBak') {
await apiDelGlobalBak()
} else if (api === '/updateGlobalBak') {
await apiUpdateGlobalBak()
} else if (api === '/saveGlobalBak') {
await apiSaveGlobalBak()
} else if (api === '/impGlobalBak') {
await apiImpGlobalBak()
} else if (api === '/revertGlobalBak') {
await apiRevertGlobalBak()
} else if (api === '/runScript') {
await apiRunScript()
} else if (api === '/saveData') {
await apiSaveData()
} else if (api === '/surge') {
await apiSurge()
} else if (api === '/update') {
await apiUpdate()
const apiHandlers = {
'/save': apiSave,
'/addAppSub': apiAddAppSub,
'/deleteAppSub': apiDeleteAppSub,
'/reloadAppSub': apiReloadAppSub,
'/delGlobalBak': apiDelGlobalBak,
'/updateGlobalBak': apiUpdateGlobalBak,
'/saveGlobalBak': apiSaveGlobalBak,
'/impGlobalBak': apiImpGlobalBak,
'/revertGlobalBak': apiRevertGlobalBak,
'/runScript': apiRunScript,
'/saveData': apiSaveData,
'/surge': apiSurge,
'/update': apiUpdate,
}

for (const [key, handler] of Object.entries(apiHandlers)) {
if (api === key || api.startsWith(`${key}?`)) {
await handler()
break
}
}
}

Expand Down Expand Up @@ -739,6 +736,15 @@ async function apiAddAppSub() {
$.json = getBoxData()
}

async function apiDeleteAppSub() {
const sub = $.toObj($request.body)
// 添加订阅
const usercfgs = getUserCfgs()
usercfgs.appsubs = usercfgs.appsubs.filter(e => e.url !== sub.url)
$.setjson(usercfgs, $.KEY_usercfgs)
$.json = getBoxData()
}

async function apiReloadAppSub() {
const sub = $.toObj($request.body)
if (sub) {
Expand Down
12 changes: 12 additions & 0 deletions box/release/box.release.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
{
"releases": [
{
"version": "0.19.11",
"tags": ["beta"],
"author": "@GideonSenku",
"msg": "feat(boxjs): 新增 /api/deleteAppSub 删除订阅",
"notes": [
{
"name": "新增 API",
"descs": ["本次更新主要面向开发者"]
}
]
},
{
"version": "0.19.10",
"tags": ["beta"],
Expand Down
12 changes: 12 additions & 0 deletions box/release/box.release.tf.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
{
"releases": [
{
"version": "0.19.11",
"tags": ["beta"],
"author": "@GideonSenku",
"msg": "feat(boxjs): 新增 /api/deleteAppSub 删除订阅",
"notes": [
{
"name": "新增 API",
"descs": ["本次更新主要面向开发者"]
}
]
},
{
"version": "0.19.10",
"tags": ["beta"],
Expand Down
56 changes: 31 additions & 25 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.10'
$.version = '0.19.11'
$.versionType = 'beta'

// 发出的请求需要需要 Surge、QuanX 的 rewrite
Expand Down Expand Up @@ -277,30 +277,27 @@ async function handleQuery() {
async function handleApi() {
const [, api] = $.path.split('/api')

if (api === '/save' || api.startsWith('/save?')) {
await apiSave()
} else if (api === '/addAppSub') {
await apiAddAppSub()
} else if (api === '/reloadAppSub') {
await apiReloadAppSub()
} else if (api === '/delGlobalBak') {
await apiDelGlobalBak()
} else if (api === '/updateGlobalBak') {
await apiUpdateGlobalBak()
} else if (api === '/saveGlobalBak') {
await apiSaveGlobalBak()
} else if (api === '/impGlobalBak') {
await apiImpGlobalBak()
} else if (api === '/revertGlobalBak') {
await apiRevertGlobalBak()
} else if (api === '/runScript') {
await apiRunScript()
} else if (api === '/saveData') {
await apiSaveData()
} else if (api === '/surge') {
await apiSurge()
} else if (api === '/update') {
await apiUpdate()
const apiHandlers = {
'/save': apiSave,
'/addAppSub': apiAddAppSub,
'/deleteAppSub': apiDeleteAppSub,
'/reloadAppSub': apiReloadAppSub,
'/delGlobalBak': apiDelGlobalBak,
'/updateGlobalBak': apiUpdateGlobalBak,
'/saveGlobalBak': apiSaveGlobalBak,
'/impGlobalBak': apiImpGlobalBak,
'/revertGlobalBak': apiRevertGlobalBak,
'/runScript': apiRunScript,
'/saveData': apiSaveData,
'/surge': apiSurge,
'/update': apiUpdate,
}

for (const [key, handler] of Object.entries(apiHandlers)) {
if (api === key || api.startsWith(`${key}?`)) {
await handler()
break
}
}
}

Expand Down Expand Up @@ -739,6 +736,15 @@ async function apiAddAppSub() {
$.json = getBoxData()
}

async function apiDeleteAppSub() {
const sub = $.toObj($request.body)
// 添加订阅
const usercfgs = getUserCfgs()
usercfgs.appsubs = usercfgs.appsubs.filter(e => e.url !== sub.url)
$.setjson(usercfgs, $.KEY_usercfgs)
$.json = getBoxData()
}

async function apiReloadAppSub() {
const sub = $.toObj($request.body)
if (sub) {
Expand Down

0 comments on commit 8596c26

Please sign in to comment.