feat: 快捷脚本支持 await; 脚本操作支持 produceArtifact

This commit is contained in:
xream 2024-01-13 13:40:34 +08:00
parent 3aacd26b79
commit 164ae9a7a8
No known key found for this signature in database
GPG Key ID: 1D2C5225471789F9
2 changed files with 20 additions and 6 deletions

View File

@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.14.148",
"version": "2.14.149",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {

View File

@ -7,6 +7,8 @@ import lodash from 'lodash';
import $ from '@/core/app';
import { hex_md5 } from '@/vendor/md5';
import { ProxyUtils } from '@/core/proxy-utils';
import { produceArtifact } from '@/restful/sync';
import env from '@/utils/env';
import { getFlowHeaders, parseFlowHeaders, flowTransfer } from '@/utils/flow';
@ -319,11 +321,12 @@ function ScriptOperator(script, targetPlatform, $arguments, source) {
`async function operator(input = []) {
let proxies
if (Array.isArray(input)) {
proxies = input
return proxies.map(($server = {}) => {
let list = []
for await (let $server of input) {
${script}
return $server
})
list.push($server)
}
return list
} else {
let { $content, $files } = input
${script}
@ -783,6 +786,7 @@ function createDynamicFunction(name, script, $arguments) {
'ProxyUtils',
'scriptResourceCache',
'flowUtils',
'produceArtifact',
`${script}\n return ${name}`,
)(
$arguments,
@ -797,6 +801,7 @@ function createDynamicFunction(name, script, $arguments) {
ProxyUtils,
scriptResourceCache,
flowUtils,
produceArtifact,
);
} else {
return new Function(
@ -806,8 +811,17 @@ function createDynamicFunction(name, script, $arguments) {
'ProxyUtils',
'scriptResourceCache',
'flowUtils',
'produceArtifact',
`${script}\n return ${name}`,
)($arguments, $, lodash, ProxyUtils, scriptResourceCache, flowUtils);
)(
$arguments,
$,
lodash,
ProxyUtils,
scriptResourceCache,
flowUtils,
produceArtifact,
);
}
}