MCPcopy Create free account
hub / github.com/chavyleung/scripts / apiSurge

Function apiSurge

box/chavy.boxjs.js:982–1006  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

980}
981
982async function apiSurge() {
983 const opts = $.toObj($request.body)
984 const httpapi = $.getdata('@chavy_boxjs_userCfgs.httpapi')
985 const ishttpapi = /.*?@.*?:[0-9]+/.test(httpapi)
986 if (
987 $.isSurge() &&
988 !$.isLoon() &&
989 !$.isShadowrocket() &&
990 !$.isStash() &&
991 ishttpapi
992 ) {
993 const [key, prefix] = httpapi.split('@')
994 opts.url = `http://${prefix}/${opts.url}`
995 opts.headers = {
996 'X-Key': key,
997 'Accept': 'application/json, text/plain, */*'
998 }
999 await new Promise((resolve) => {
1000 $[opts.method.toLowerCase()](opts, (_, __, resp) => {
1001 $.json = JSON.parse(resp)
1002 resolve($.json)
1003 })
1004 })
1005 }
1006}
1007
1008async function apiSaveData() {
1009 const { key: dataKey, val: dataVal } = $.toObj($request.body)

Callers

nothing calls this directly

Calls 6

toObjMethod · 0.45
getdataMethod · 0.45
isSurgeMethod · 0.45
isLoonMethod · 0.45
isShadowrocketMethod · 0.45
isStashMethod · 0.45

Tested by

no test coverage detected