From 1b4c046b7522eaa71c06b47ccc9b2a48f7086eff Mon Sep 17 00:00:00 2001 From: xream Date: Thu, 27 Feb 2025 23:37:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20mihomo=20=E8=A6=86=E5=86=99=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E5=A4=9A=E6=AC=A1=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- .../src/core/proxy-utils/processors/index.js | 23 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/backend/package.json b/backend/package.json index 25a7988..b75086f 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.16.58", + "version": "2.16.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/processors/index.js b/backend/src/core/proxy-utils/processors/index.js index 2929ea7..8d98197 100644 --- a/backend/src/core/proxy-utils/processors/index.js +++ b/backend/src/core/proxy-utils/processors/index.js @@ -366,12 +366,20 @@ function ScriptOperator(script, targetPlatform, $arguments, source, $options) { if (output?.$file?.type === 'mihomoProfile') { try { let patch = YAML.safeLoad(script); + let config; + if (output?.$content) { + try { + config = YAML.safeLoad(output?.$content); + } catch (e) { + $.error(e.message ?? e); + } + } // if (typeof patch !== 'object') patch = {}; if (typeof patch !== 'object') throw new Error('patch is not an object'); output.$content = ProxyUtils.yaml.safeDump( deepMerge( - { + config || { proxies: await produceArtifact({ type: output?.$file?.sourceType || @@ -414,7 +422,15 @@ function ScriptOperator(script, targetPlatform, $arguments, source, $options) { if($file.type === 'mihomoProfile') { ${script} if(typeof main === 'function') { - const config = { + let config; + if ($content) { + try { + config = ProxyUtils.yaml.safeLoad($content); + } catch (e) { + console.log(e.message ?? e); + } + } + $content = ProxyUtils.yaml.safeDump(await main(config || { proxies: await produceArtifact({ type: $file.sourceType || 'collection', name: $file.sourceName, @@ -424,8 +440,7 @@ function ScriptOperator(script, targetPlatform, $arguments, source, $options) { 'delete-underscore-fields': true } }), - } - $content = ProxyUtils.yaml.safeDump(await main(config)) + })) } } else { ${script}