Skip to content

Commit 3086083

Browse files
committed
更新[EnvJs]: 新增 getScript()、runScript()
1 parent 778cfe8 commit 3086083

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

Env.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,33 @@ function Env(name, opts) {
2020
}
2121

2222
isSurge() {
23-
return 'undefined' !== typeof $httpClient
23+
return 'undefined' !== typeof $httpClient && 'undefined' === typeof $loon
2424
}
2525

2626
isLoon() {
2727
return 'undefined' !== typeof $loon
2828
}
2929

30+
getScript(url) {
31+
return new Promise((resolve) => {
32+
$.get({ url }, (err, resp, body) => resolve(body))
33+
})
34+
}
35+
36+
runScript(script) {
37+
return new Promise((resolve) => {
38+
const httpapi = this.getdata('@chavy_boxjs_userCfgs.httpapi')
39+
console.log(httpapi)
40+
const [key, addr] = httpapi.split('@')
41+
const opts = {
42+
url: `http://${addr}/v1/scripting/evaluate`,
43+
body: { script_text: script, mock_type: 'cron', timeout: 5 },
44+
headers: { 'X-Key': key, 'Accept': '*/*' }
45+
}
46+
$.post(opts, (err, resp, body) => resolve(body))
47+
})
48+
}
49+
3050
loaddata() {
3151
if (this.isNode()) {
3252
this.fs = this.fs ? this.fs : require('fs')

Env.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)