Skip to content

Commit

Permalink
feat: 支持转换 surge ip-cidr6 至 quantumult x ip6-cidr
Browse files Browse the repository at this point in the history
  • Loading branch information
geekdada committed May 5, 2020
1 parent 1e51415 commit c823677
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/generator/__tests__/template.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,19 @@ test('base64', t => {

test('quantumultx filter 1', t => {
const body = `{{ str | quantumultx }}`;
const str = `PROCESS-NAME,Telegram,Proxy,no-resolve // test rule`;
const result = templateEngine.renderString(body, {
str,
});

t.is(result, '');
t.is(
templateEngine.renderString(body, {
str: `PROCESS-NAME,Telegram,Proxy,no-resolve // test rule`,
}),
''
);
t.is(
templateEngine.renderString(body, {
str: 'IP-CIDR6, 2001:4860:4860::8888/32, DIRECT',
}),
'IP6-CIDR, 2001:4860:4860::8888/32, DIRECT'
);
});

test('quantumultx filter 2', t => {
Expand Down
4 changes: 4 additions & 0 deletions lib/generator/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ export function getEngine(templateDir: string): nunjucks.Environment {
matched &&
QUANTUMULT_X_SUPPORTED_RULE.some(s => matched[1] === s)
) {
if (matched[1] === 'IP-CIDR6') {
return item.replace(/IP-CIDR6/i, 'IP6-CIDR');
}

// 过滤出支持的规则类型
return item;
}
Expand Down
1 change: 1 addition & 0 deletions lib/utils/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const QUANTUMULT_X_SUPPORTED_RULE: ReadonlyArray<string> = [
'DOMAIN-SUFFIX',
'DOMAIN-KEYWORD',
'IP-CIDR',
'IP-CIDR6',
'GEOIP',
'FINAL',
];
Expand Down

0 comments on commit c823677

Please sign in to comment.