mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-04-23 22:29:32 +08:00
feat: 脚本操作支持节点快捷脚本. 语法与 Shadowrocket 脚本类似
``` $server.name = '前缀-' + $server.name $server.ecn = true $server['test-url'] = 'http://1.0.0.1/generate_204' ```
This commit is contained in:
parent
3e5f3eafdd
commit
3e30a35bc4
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sub-store",
|
||||
"version": "2.14.88",
|
||||
"version": "2.14.89",
|
||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
||||
"main": "src/main.js",
|
||||
"scripts": {
|
||||
|
@ -311,6 +311,23 @@ function ScriptOperator(script, targetPlatform, $arguments, source) {
|
||||
})();
|
||||
return output;
|
||||
},
|
||||
nodeFunc: async (proxies) => {
|
||||
let output = proxies;
|
||||
await (async function () {
|
||||
const operator = createDynamicFunction(
|
||||
'operator',
|
||||
`async function operator(proxies = []) {
|
||||
return proxies.map(($server = {}) => {
|
||||
${script}
|
||||
return $server
|
||||
})
|
||||
}`,
|
||||
$arguments,
|
||||
);
|
||||
output = operator(proxies, targetPlatform, { source, ...env });
|
||||
})();
|
||||
return output;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@ -620,9 +637,33 @@ async function ApplyOperator(operator, objs) {
|
||||
const output_ = await operator.func(output);
|
||||
if (output_) output = output_;
|
||||
} catch (err) {
|
||||
// print log and skip this operator
|
||||
$.error(`Cannot apply operator ${operator.name}! Reason: ${err}`);
|
||||
throw new Error(`脚本操作失败 ${err.message ?? err}`);
|
||||
$.error(
|
||||
`Cannot apply operator ${operator.name}(function operator)! Reason: ${err}`,
|
||||
);
|
||||
let funcErr = '';
|
||||
let funcErrMsg = `${err.message ?? err}`;
|
||||
if (funcErrMsg.includes('$server is not defined')) {
|
||||
funcErr = '';
|
||||
} else {
|
||||
funcErr = `执行 function operator 失败 ${funcErrMsg}; `;
|
||||
}
|
||||
try {
|
||||
const output_ = await operator.nodeFunc(output);
|
||||
if (output_) output = output_;
|
||||
} catch (err) {
|
||||
$.error(
|
||||
`Cannot apply operator ${operator.name}(node script)! Reason: ${err}`,
|
||||
);
|
||||
let nodeErr = '';
|
||||
let nodeErrMsg = `${err.message ?? err}`;
|
||||
if (funcErr && nodeErrMsg === funcErrMsg) {
|
||||
nodeErr = '';
|
||||
funcErr = `执行失败 ${funcErrMsg}`;
|
||||
} else {
|
||||
nodeErr = `执行节点快捷脚本 失败 ${nodeErr}`;
|
||||
}
|
||||
throw new Error(`脚本操作 ${funcErr}${nodeErr}`);
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user