diff --git a/backend/package.json b/backend/package.json index 2b9d65c9..9e524b1a 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.21.51", + "version": "2.21.52", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/core/proxy-utils/preprocessors/index.js b/backend/src/core/proxy-utils/preprocessors/index.js index f3c560e6..235fb7b7 100644 --- a/backend/src/core/proxy-utils/preprocessors/index.js +++ b/backend/src/core/proxy-utils/preprocessors/index.js @@ -11,6 +11,13 @@ export function normalizeClashYaml(raw) { return raw; } + try { + const content = safeLoad(raw); + if (!Array.isArray(content.proxies) || content.proxies.length === 0) + return raw; + } catch (e) { + return raw; + } // 防止 VLESS 节点 reality-opts 里的 short-id 被 YAML 标量推断成数字 // 例如 08 / 0088 在部分内核重新解析时会触发 invalid REALITY short ID return raw.replace(/short-id:([ \t]*[^#\n,}]*)/g, (matched, value) => { diff --git a/backend/src/restful/file.js b/backend/src/restful/file.js index 70d33f73..8a0714e9 100644 --- a/backend/src/restful/file.js +++ b/backend/src/restful/file.js @@ -9,7 +9,6 @@ import { InternalServerError, } from '@/restful/errors'; import { produceArtifact } from '@/restful/sync'; -import { normalizeClashYaml } from '@/core/proxy-utils/preprocessors'; import { formatDateTime } from '@/utils'; export default function register($app) { @@ -205,7 +204,7 @@ async function getFile(req, res, next) { if (output?.$options?._res?.status) { res.status(output.$options._res.status); } - res.send(normalizeClashYaml(output?.$content ?? '')); + res.send(output?.$content ?? ''); } catch (err) { $.notify( `🌍 Sub-Store 下载文件失败`, diff --git a/backend/src/restful/preview.js b/backend/src/restful/preview.js index 03ef0479..a2db5689 100644 --- a/backend/src/restful/preview.js +++ b/backend/src/restful/preview.js @@ -5,6 +5,7 @@ import { success, failed } from './response'; import download from '@/utils/download'; import { SUBS_KEY } from '@/constants'; import $ from '@/core/app'; +import { normalizeClashYaml } from '@/core/proxy-utils/preprocessors'; export default function register($app) { $app.post('/api/preview/sub', compareSub); @@ -89,7 +90,7 @@ async function previewFile(req, res) { // produce success(res, { original: filesContent, - processed: processed?.$content ?? '', + processed: normalizeClashYaml(processed?.$content ?? ''), }); } catch (err) { $.error(err.message ?? err); diff --git a/backend/src/restful/sync.js b/backend/src/restful/sync.js index a09b9585..b88b406e 100644 --- a/backend/src/restful/sync.js +++ b/backend/src/restful/sync.js @@ -13,6 +13,7 @@ import download from '@/utils/download'; import { ProxyUtils } from '@/core/proxy-utils'; import { RuleUtils } from '@/core/rule-utils'; import { syncToGist } from '@/restful/artifacts'; +import { normalizeClashYaml } from '@/core/proxy-utils/preprocessors'; export default function register($app) { // Initialization @@ -596,6 +597,8 @@ async function produceArtifact({ ) : { $content: filesContent, $files: files, $options }; + processed.$content = normalizeClashYaml(processed?.$content ?? ''); + return (all ? processed : processed?.$content) ?? ''; } }