mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-28 17:41:54 +08:00
Refactor: move China IPv4 to https://github.com/SukkaW/chnroutes2-optimized
This commit is contained in:
@@ -1,41 +1,15 @@
|
||||
import { fetchRemoteTextByLine } from './lib/fetch-text-by-line';
|
||||
import { task } from './trace';
|
||||
|
||||
import { contains as containsCidr, exclude as excludeCidr } from 'fast-cidr-tools';
|
||||
import { createMemoizedPromise } from './lib/memo-promise';
|
||||
import { CN_CIDR_MISSING_IN_CHNROUTE, NON_CN_CIDR_INCLUDED_IN_CHNROUTE } from './constants/cidr';
|
||||
import { appendArrayInPlace } from 'foxts/append-array-in-place';
|
||||
import { IPListOutput } from './lib/rules/ip';
|
||||
import { createFileDescription } from './constants/description';
|
||||
|
||||
const PROBE_CHN_CIDR_V4 = [
|
||||
// NetEase Hangzhou
|
||||
'223.252.196.38',
|
||||
// Aliyun ShenZhen
|
||||
'120.78.92.171'
|
||||
];
|
||||
|
||||
export const getChnCidrPromise = createMemoizedPromise(async function getChnCidr() {
|
||||
const [_cidr4, cidr6] = await Promise.all([
|
||||
fetchRemoteTextByLine('https://raw.githubusercontent.com/misakaio/chnroutes2/master/chnroutes.txt', true).then(Array.fromAsync<string>),
|
||||
return Promise.all([
|
||||
fetchRemoteTextByLine('https://chnroutes2.cdn.skk.moe/chnroutes.txt', true).then(Array.fromAsync<string>),
|
||||
fetchRemoteTextByLine('https://gaoyifan.github.io/china-operator-ip/china6.txt', true).then(Array.fromAsync<string>)
|
||||
]);
|
||||
|
||||
const cidr4 = excludeCidr(
|
||||
appendArrayInPlace(_cidr4, CN_CIDR_MISSING_IN_CHNROUTE),
|
||||
NON_CN_CIDR_INCLUDED_IN_CHNROUTE,
|
||||
true
|
||||
);
|
||||
|
||||
for (const probeIp of PROBE_CHN_CIDR_V4) {
|
||||
if (!containsCidr(cidr4, PROBE_CHN_CIDR_V4)) {
|
||||
const err = new TypeError('chnroutes missing probe IP');
|
||||
err.cause = probeIp;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
return [cidr4, cidr6] as const;
|
||||
});
|
||||
|
||||
export const buildChnCidr = task(require.main === module, __filename)(async (span) => {
|
||||
|
||||
Reference in New Issue
Block a user