mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 01:00:34 +08:00
Log incompatible rules when transform to clash
This commit is contained in:
parent
536046b429
commit
855687e89e
@ -1,20 +1,26 @@
|
|||||||
|
import picocolors from 'picocolors';
|
||||||
|
|
||||||
const identity = <T>(x: T): T => x;
|
const identity = <T>(x: T): T => x;
|
||||||
|
const unsupported = Symbol('unsupported');
|
||||||
|
|
||||||
// https://dreamacro.github.io/clash/configuration/rules.html
|
// https://dreamacro.github.io/clash/configuration/rules.html
|
||||||
const PROCESSOR: Record<string, (raw: string, type: string, value: string) => string> = {
|
const PROCESSOR: Record<string, ((raw: string, type: string, value: string) => string) | typeof unsupported> = {
|
||||||
DOMAIN: identity,
|
DOMAIN: identity,
|
||||||
'DOMAIN-SUFFIX': identity,
|
'DOMAIN-SUFFIX': identity,
|
||||||
'DOMAIN-KEYWORD': identity,
|
'DOMAIN-KEYWORD': identity,
|
||||||
GEOIP: identity,
|
GEOIP: identity,
|
||||||
'IP-CIDR': identity,
|
'IP-CIDR': identity,
|
||||||
'IP-CIDR6': identity,
|
'IP-CIDR6': identity,
|
||||||
|
'IP-ASN': identity,
|
||||||
'SRC-IP-CIDR': identity,
|
'SRC-IP-CIDR': identity,
|
||||||
'SRC-PORT': identity,
|
'SRC-PORT': identity,
|
||||||
'DST-PORT': identity,
|
'DST-PORT': identity,
|
||||||
'PROCESS-NAME': identity,
|
'PROCESS-NAME': identity,
|
||||||
'PROCESS-PATH': identity,
|
'PROCESS-PATH': identity,
|
||||||
'DEST-PORT': (_raw, type, value) => `DST-PORT,${value}`,
|
'DEST-PORT': (_raw, type, value) => `DST-PORT,${value}`,
|
||||||
'IN-PORT': (_raw, type, value) => `SRC-PORT,${value}`
|
'IN-PORT': (_raw, type, value) => `SRC-PORT,${value}`,
|
||||||
|
'URL-REGEX': unsupported,
|
||||||
|
'USER-AGENT': unsupported
|
||||||
};
|
};
|
||||||
|
|
||||||
export const surgeRulesetToClashClassicalTextRuleset = (rules: string[] | Set<string>) => {
|
export const surgeRulesetToClashClassicalTextRuleset = (rules: string[] | Set<string>) => {
|
||||||
@ -34,7 +40,12 @@ export const surgeRulesetToClashClassicalTextRuleset = (rules: string[] | Set<st
|
|||||||
}
|
}
|
||||||
const value = cur.slice(i + 1);
|
const value = cur.slice(i + 1);
|
||||||
if (type in PROCESSOR) {
|
if (type in PROCESSOR) {
|
||||||
acc.push(PROCESSOR[type](cur, type, value));
|
const proc = PROCESSOR[type];
|
||||||
|
if (proc !== unsupported) {
|
||||||
|
acc.push(proc(cur, type, value));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log(picocolors.yellow(`[clash] unknown rule type: ${type}`), cur);
|
||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
}, []);
|
}, []);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user