From 6c553e430cadca1f783c4feca68db5dc1f8d64ea Mon Sep 17 00:00:00 2001 From: xream Date: Sat, 27 Dec 2025 17:09:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9A=A0=EF=B8=8F=20BREAKING=20CHANGE?= =?UTF-8?q?=20=E8=84=9A=E6=9C=AC=E4=B8=AD=E7=9A=84=20=E7=AC=AC=E4=B8=89?= =?UTF-8?q?=E4=B8=AA=E5=8F=82=E6=95=B0=20context=20=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E5=85=B1=E4=BA=AB=E7=9A=84=E4=B8=8A=E4=B8=8B?= =?UTF-8?q?=E6=96=87,=20=E5=8F=AF=E8=87=AA=E7=94=B1=E6=93=8D=E4=BD=9C.=20?= =?UTF-8?q?=E5=8E=9F=E6=9C=AC=E7=9A=84=20env=20=E4=BF=A1=E6=81=AF,=20?= =?UTF-8?q?=E7=8E=B0=E5=9C=A8=E4=B8=BA=20context.env?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/core/proxy-utils/index.js | 2 ++ .../src/core/proxy-utils/processors/index.js | 34 ++++++++++++++----- scripts/demo.js | 4 ++- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/backend/package.json b/backend/package.json index ea26a661..fad60236 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.20.58", + "version": "2.20.59", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/core/proxy-utils/index.js b/backend/src/core/proxy-utils/index.js index d4638246..603ab1f8 100644 --- a/backend/src/core/proxy-utils/index.js +++ b/backend/src/core/proxy-utils/index.js @@ -99,6 +99,7 @@ async function processFn( source, $options, ) { + let context = {}; for (const item of operators) { if (item.disabled) { $.log( @@ -222,6 +223,7 @@ async function processFn( $arguments, source, $options, + context, ); } else { processor = PROXY_PROCESSORS[item.type](item.args || {}); diff --git a/backend/src/core/proxy-utils/processors/index.js b/backend/src/core/proxy-utils/processors/index.js index 9c2cd1cb..9b04aa9f 100644 --- a/backend/src/core/proxy-utils/processors/index.js +++ b/backend/src/core/proxy-utils/processors/index.js @@ -371,7 +371,16 @@ function RegexDeleteOperator(regex) { 1. This function name should be `operator`! 2. Always declare variables before using them! */ -function ScriptOperator(script, targetPlatform, $arguments, source, $options) { +function ScriptOperator( + script, + targetPlatform, + $arguments, + source, + $options, + context, +) { + context.source = source; + context.env = env; return { name: 'Script Operator', func: async (proxies) => { @@ -423,7 +432,7 @@ function ScriptOperator(script, targetPlatform, $arguments, source, $options) { $arguments, $options, ); - output = operator(proxies, targetPlatform, { source, ...env }); + output = operator(proxies, targetPlatform, context); })(); return output; }, @@ -432,7 +441,7 @@ function ScriptOperator(script, targetPlatform, $arguments, source, $options) { await (async function () { const operator = createDynamicFunction( 'operator', - `async function operator(input = []) { + `async function operator(input = [], targetPlatform, context) { if (input && (input.$files || input.$content)) { let { $content, $files, $options, $file } = input if($file.type === 'mihomoProfile') { @@ -475,7 +484,7 @@ function ScriptOperator(script, targetPlatform, $arguments, source, $options) { $arguments, $options, ); - output = operator(proxies, targetPlatform, { source, ...env }); + output = operator(proxies, targetPlatform, context); })(); return output; }, @@ -949,7 +958,16 @@ function TypeFilter(input) { 1. This function name should be `filter`! 2. Always declare variables before using them! */ -function ScriptFilter(script, targetPlatform, $arguments, source, $options) { +function ScriptFilter( + script, + targetPlatform, + $arguments, + source, + $options, + context, +) { + context.source = source; + context.env = env; return { name: 'Script Filter', func: async (proxies) => { @@ -961,7 +979,7 @@ function ScriptFilter(script, targetPlatform, $arguments, source, $options) { $arguments, $options, ); - output = filter(proxies, targetPlatform, { source, ...env }); + output = filter(proxies, targetPlatform, context); })(); return output; }, @@ -970,7 +988,7 @@ function ScriptFilter(script, targetPlatform, $arguments, source, $options) { await (async function () { const filter = createDynamicFunction( 'filter', - `async function filter(input = []) { + `async function filter(input = [], targetPlatform, context) { let proxies = input let list = [] const fn = async ($server) => { @@ -984,7 +1002,7 @@ function ScriptFilter(script, targetPlatform, $arguments, source, $options) { $arguments, $options, ); - output = filter(proxies, targetPlatform, { source, ...env }); + output = filter(proxies, targetPlatform, context); })(); return output; }, diff --git a/scripts/demo.js b/scripts/demo.js index d1e93b50..f26a7a7f 100644 --- a/scripts/demo.js +++ b/scripts/demo.js @@ -257,7 +257,9 @@ function operator(proxies = [], targetPlatform, context) { // 可参考: // 1. https://t.me/zhetengsha/948 - // context 为传入的上下文 + // context 为传入的上下文, 可在多个脚本中共享使用 + // 其中 env 为 环境信息, 包含运行版本和其他后端信息 + // 其中 source 为 订阅和组合订阅的数据, 有三种情况, 按需判断 (若只需要取订阅/组合订阅名称 直接用 `_subName` `_subDisplayName` `_collectionName` `_collectionDisplayName` 即可) // 若存在 `source._collection` 且 `source._collection.subscriptions` 中的 key 在 `source` 上也存在, 说明输出结果为组合订阅, 但是脚本设置在单条订阅上