| 925 | } |
| 926 | |
| 927 | async function apiSurge() { |
| 928 | const opts = $.toObj($request.body) |
| 929 | const httpapi = $.getdata('@chavy_boxjs_userCfgs.httpapi') |
| 930 | const ishttpapi = /.*?@.*?:[0-9]+/.test(httpapi) |
| 931 | if ( |
| 932 | $.isSurge() && |
| 933 | !$.isLoon() && |
| 934 | !$.isShadowrocket() && |
| 935 | !$.isStash() && |
| 936 | ishttpapi |
| 937 | ) { |
| 938 | const [key, prefix] = httpapi.split('@') |
| 939 | opts.url = `http://${prefix}/${opts.url}` |
| 940 | opts.headers = { |
| 941 | 'X-Key': key, |
| 942 | 'Accept': 'application/json, text/plain, */*' |
| 943 | } |
| 944 | await new Promise((resolve) => { |
| 945 | $[opts.method.toLowerCase()](opts, (_, __, resp) => { |
| 946 | $.json = JSON.parse(resp) |
| 947 | resolve($.json) |
| 948 | }) |
| 949 | }) |
| 950 | } |
| 951 | } |
| 952 | |
| 953 | async function apiSaveData() { |
| 954 | const { key: dataKey, val: dataVal } = $.toObj($request.body) |