Chore: enable microsoft_cdn build / refine Clash transformation

This commit is contained in:
SukkaW
2023-12-20 12:03:46 +08:00
parent 809281f56b
commit c9c23ee127
2 changed files with 17 additions and 0 deletions

View File

@@ -16,10 +16,23 @@ const CLASH_SUPPORTED_RULE_TYPE = [
'PROCESS-PATH'
];
const REQUIRE_REWRITE = {
'DEST-PORT': 'DST-PORT',
'IN-PORT': 'SRC-PORT'
} as const;
export const surgeRulesetToClashClassicalTextRuleset = (rules: string[] | Set<string>) => {
const trie = Trie.from(rules);
return CLASH_SUPPORTED_RULE_TYPE.flatMap(
type => trie.find(`${type},`)
).concat(
Object.keys(REQUIRE_REWRITE).flatMap(
(type) => {
const found = trie.find(`${type},`);
return found.map(line => `${REQUIRE_REWRITE[type as keyof typeof REQUIRE_REWRITE]}${line.slice(type.length)}`);
}
)
);
};