fix: mihomo 覆写可以多次使用

This commit is contained in:
xream 2025-02-27 23:37:39 +08:00
parent 41034ceb46
commit 1b4c046b75
No known key found for this signature in database
GPG Key ID: 1D2C5225471789F9
2 changed files with 20 additions and 5 deletions

View File

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

View File

@ -366,12 +366,20 @@ function ScriptOperator(script, targetPlatform, $arguments, source, $options) {
if (output?.$file?.type === 'mihomoProfile') { if (output?.$file?.type === 'mihomoProfile') {
try { try {
let patch = YAML.safeLoad(script); 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') patch = {};
if (typeof patch !== 'object') if (typeof patch !== 'object')
throw new Error('patch is not an object'); throw new Error('patch is not an object');
output.$content = ProxyUtils.yaml.safeDump( output.$content = ProxyUtils.yaml.safeDump(
deepMerge( deepMerge(
{ config || {
proxies: await produceArtifact({ proxies: await produceArtifact({
type: type:
output?.$file?.sourceType || output?.$file?.sourceType ||
@ -414,7 +422,15 @@ function ScriptOperator(script, targetPlatform, $arguments, source, $options) {
if($file.type === 'mihomoProfile') { if($file.type === 'mihomoProfile') {
${script} ${script}
if(typeof main === 'function') { 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({ proxies: await produceArtifact({
type: $file.sourceType || 'collection', type: $file.sourceType || 'collection',
name: $file.sourceName, name: $file.sourceName,
@ -424,8 +440,7 @@ function ScriptOperator(script, targetPlatform, $arguments, source, $options) {
'delete-underscore-fields': true 'delete-underscore-fields': true
} }
}), }),
} }))
$content = ProxyUtils.yaml.safeDump(await main(config))
} }
} else { } else {
${script} ${script}