| 980 | } |
| 981 | |
| 982 | async 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 | |
| 1008 | async function apiSaveData() { |
| 1009 | const { key: dataKey, val: dataVal } = $.toObj($request.body) |