mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 17:20:35 +08:00
59 lines
2.1 KiB
TypeScript
59 lines
2.1 KiB
TypeScript
import { fetchRemoteTextByLine } from './lib/fetch-text-by-line';
|
|
import { createRuleset } from './lib/create-file';
|
|
import { processLineFromReadline } from './lib/process-line';
|
|
import { task } from './trace';
|
|
|
|
import { exclude } from 'fast-cidr-tools';
|
|
import { createMemoizedPromise } from './lib/memo-promise';
|
|
import { CN_CIDR_NOT_INCLUDED_IN_CHNROUTE, NON_CN_CIDR_INCLUDED_IN_CHNROUTE } from './constants/cidr';
|
|
import { appendArrayInPlace } from './lib/append-array-in-place';
|
|
import { output } from './lib/misc';
|
|
|
|
export const getChnCidrPromise = createMemoizedPromise(async () => {
|
|
const cidr4 = await processLineFromReadline(await fetchRemoteTextByLine('https://raw.githubusercontent.com/misakaio/chnroutes2/master/chnroutes.txt'));
|
|
const cidr6 = await processLineFromReadline(await fetchRemoteTextByLine('https://gaoyifan.github.io/china-operator-ip/china6.txt'));
|
|
|
|
appendArrayInPlace(cidr4, CN_CIDR_NOT_INCLUDED_IN_CHNROUTE);
|
|
return [exclude(cidr4, NON_CN_CIDR_INCLUDED_IN_CHNROUTE, true), cidr6] as const;
|
|
});
|
|
|
|
export const buildChnCidr = task(require.main === module, __filename)(async (span) => {
|
|
const [filteredCidr4, cidr6] = await span.traceChildAsync('download chnroutes2', getChnCidrPromise);
|
|
|
|
// Can not use SHARED_DESCRIPTION here as different license
|
|
const description = [
|
|
'License: CC BY-SA 2.0',
|
|
'Homepage: https://ruleset.skk.moe',
|
|
'GitHub: https://github.com/SukkaW/Surge',
|
|
''
|
|
];
|
|
|
|
// Can not use createRuleset here, as Clash support advanced ipset syntax
|
|
return Promise.all([
|
|
createRuleset(
|
|
span,
|
|
'Sukka\'s Ruleset - Mainland China IPv4 CIDR',
|
|
[
|
|
...description,
|
|
'Data from https://misaka.io (misakaio @ GitHub)'
|
|
],
|
|
new Date(),
|
|
filteredCidr4,
|
|
'ipcidr',
|
|
output('china_ip', 'ip')
|
|
),
|
|
createRuleset(
|
|
span,
|
|
'Sukka\'s Ruleset - Mainland China IPv6 CIDR',
|
|
[
|
|
...description,
|
|
'Data from https://github.com/gaoyifan/china-operator-ip'
|
|
],
|
|
new Date(),
|
|
cidr6,
|
|
'ipcidr6',
|
|
output('china_ip_ipv6', 'ip')
|
|
)
|
|
]);
|
|
});
|