|
1 | 1 | const $ = new Env('BoxJs') |
2 | 2 | $.domain = '8.8.8.8' |
3 | 3 |
|
4 | | -$.version = '0.6.4' |
| 4 | +$.version = '0.6.5' |
5 | 5 | $.versionType = 'beta' |
6 | 6 | $.KEY_sessions = 'chavy_boxjs_sessions' |
7 | 7 | $.KEY_versions = 'chavy_boxjs_versions' |
@@ -469,10 +469,17 @@ async function handleApi() { |
469 | 469 | // 运行脚本 |
470 | 470 | else if (data.cmd === 'runScript') { |
471 | 471 | const httpapi = $.getdata('@chavy_boxjs_userCfgs.httpapi') |
472 | | - if (/.*?@.*?:[0-9]+/.test(httpapi)) { |
| 472 | + const ishttpapi = /.*?@.*?:[0-9]+/.test(httpapi) |
| 473 | + console.log(ishttpapi) |
| 474 | + if ($.isSurge() && ishttpapi) { |
473 | 475 | await $.getScript(data.val.script).then((script) => $.runScript(script)) |
474 | 476 | } else { |
475 | | - $.msg($.name, '请先设置 http-api !') |
| 477 | + await $.getScript(data.val.script).then((script) => { |
| 478 | + // 避免被执行脚本误认为是 rewrite 环境 |
| 479 | + // 所以需要 `$request = undefined` |
| 480 | + $request = undefined |
| 481 | + eval(script) |
| 482 | + }) |
476 | 483 | } |
477 | 484 | } |
478 | 485 | } |
@@ -1038,7 +1045,7 @@ function printHtml(data, curapp = null, curview = 'app') { |
1038 | 1045 | <v-subheader v-if="Array.isArray(ui.curapp.settings)"> |
1039 | 1046 | 应用设置 ({{ ui.curapp.settings.length }}) |
1040 | 1047 | <v-spacer></v-spacer> |
1041 | | - <v-btn v-if="box.syscfgs.env === 'Surge' && ui.curapp.script" icon @click="onRunScript"><v-icon color="green">mdi-play-circle</v-icon></v-btn> |
| 1048 | + <v-btn v-if="ui.curapp.script" icon @click="onRunScript"><v-icon color="green">mdi-play-circle</v-icon></v-btn> |
1042 | 1049 | </v-subheader> |
1043 | 1050 | <v-form class="pl-4 pr-4"> |
1044 | 1051 | <template v-for="(setting, settingIdx) in ui.curapp.settings"> |
@@ -1067,7 +1074,7 @@ function printHtml(data, curapp = null, curview = 'app') { |
1067 | 1074 | <v-subheader> |
1068 | 1075 | 当前会话 ({{ ui.curapp.datas.length }}) |
1069 | 1076 | <v-spacer></v-spacer> |
1070 | | - <v-btn v-if="box.syscfgs.env === 'Surge' && ui.curapp.script" icon @click="onRunScript"><v-icon color="green">mdi-play-circle</v-icon></v-btn> |
| 1077 | + <v-btn v-if="ui.curapp.script" icon @click="onRunScript"><v-icon color="green">mdi-play-circle</v-icon></v-btn> |
1071 | 1078 | <v-menu bottom left> |
1072 | 1079 | <template v-slot:activator="{ on }"> |
1073 | 1080 | <v-btn icon v-on="on"><v-icon>mdi-dots-vertical</v-icon></v-btn> |
@@ -2012,13 +2019,17 @@ function printHtml(data, curapp = null, curview = 'app') { |
2012 | 2019 | }) |
2013 | 2020 | }, |
2014 | 2021 | onRunScript() { |
| 2022 | + this.ui.overlay.show = true |
| 2023 | +
|
2015 | 2024 | // const [key, addr] = this.box.usercfgs.httpapi.split('@') |
2016 | 2025 | // const url = 'http://' + addr + '/v1/scripting/evaluate' |
2017 | 2026 | // const body = { script_text: this.ui.curapp.script_text, mock_type: 'cron', timeout: 5 } |
2018 | 2027 | // const opts = {headers: { 'X-Key': key, 'Accept': '*/*' }} |
2019 | 2028 | // axios.post(url, body, opts) |
2020 | 2029 |
|
2021 | | - axios.post('/api', JSON.stringify({ cmd: 'runScript', val: this.ui.curapp })) |
| 2030 | + axios.post('/api', JSON.stringify({ cmd: 'runScript', val: this.ui.curapp })).finally(() => { |
| 2031 | + this.ui.overlay.show = false |
| 2032 | + }) |
2022 | 2033 | } |
2023 | 2034 | }, |
2024 | 2035 | mounted: function () { |
|
0 commit comments