mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-11 04:09:00 +08:00
fix: 修复 Clash Pre-processor
This commit is contained in:
parent
85a3e2ee54
commit
75012503f8
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sub-store",
|
||||
"version": "2.16.3",
|
||||
"version": "2.16.4",
|
||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
||||
"main": "src/main.js",
|
||||
"scripts": {
|
||||
|
@ -48,7 +48,7 @@ function Clash() {
|
||||
const content = safeLoad(raw);
|
||||
return content.proxies && Array.isArray(content.proxies);
|
||||
};
|
||||
const parse = function (raw) {
|
||||
const parse = function (raw, includeProxies) {
|
||||
// Clash YAML format
|
||||
|
||||
// 防止 VLESS节点 reality-opts 选项中的 short-id 被解析成 Infinity
|
||||
@ -56,35 +56,40 @@ function Clash() {
|
||||
const afterReplace = raw.replace(
|
||||
/short-id:([ ]*[^,\n}]*)/g,
|
||||
(matched, value) => {
|
||||
const afterTrim = value.trim();
|
||||
|
||||
// 为空
|
||||
if (!afterTrim || afterTrim === '') {
|
||||
return 'short-id: ""'
|
||||
}
|
||||
|
||||
// 是否被引号包裹
|
||||
if (/^(['"]).*\1$/.test(afterTrim)) {
|
||||
return `short-id: ${afterTrim}`;
|
||||
} else {
|
||||
return `short-id: "${afterTrim}"`
|
||||
}
|
||||
}
|
||||
const afterTrim = value.trim();
|
||||
|
||||
// 为空
|
||||
if (!afterTrim || afterTrim === '') {
|
||||
return 'short-id: ""';
|
||||
}
|
||||
|
||||
// 是否被引号包裹
|
||||
if (/^(['"]).*\1$/.test(afterTrim)) {
|
||||
return `short-id: ${afterTrim}`;
|
||||
} else {
|
||||
return `short-id: "${afterTrim}"`;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
const {
|
||||
proxies,
|
||||
'global-client-fingerprint': globalClientFingerprint,
|
||||
} = safeLoad(afterReplace);
|
||||
return proxies
|
||||
.map((p) => {
|
||||
// https://github.com/MetaCubeX/mihomo/blob/Alpha/docs/config.yaml#L73C1-L73C26
|
||||
if (globalClientFingerprint && !p['client-fingerprint']) {
|
||||
p['client-fingerprint'] = globalClientFingerprint;
|
||||
}
|
||||
return JSON.stringify(p);
|
||||
})
|
||||
.join('\n');
|
||||
return (
|
||||
(includeProxies ? 'proxies:\n' : '') +
|
||||
proxies
|
||||
.map((p) => {
|
||||
// https://github.com/MetaCubeX/mihomo/blob/Alpha/docs/config.yaml#L73C1-L73C26
|
||||
if (globalClientFingerprint && !p['client-fingerprint']) {
|
||||
p['client-fingerprint'] = globalClientFingerprint;
|
||||
}
|
||||
return `${includeProxies ? ' - ' : ''}${JSON.stringify(
|
||||
p,
|
||||
)}\n`;
|
||||
})
|
||||
.join('')
|
||||
);
|
||||
};
|
||||
return { name, test, parse };
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ export default async function download(
|
||||
if (preprocess) {
|
||||
try {
|
||||
if (clashPreprocessor.test(body)) {
|
||||
body = clashPreprocessor.parse(body);
|
||||
body = clashPreprocessor.parse(body, true);
|
||||
}
|
||||
} catch (e) {
|
||||
$.error(`Clash Pre-processor error: ${e}`);
|
||||
|
Loading…
x
Reference in New Issue
Block a user