|
@@ -6,7 +6,6 @@ import { createMemoizedPromise } from './lib/memo-promise';
|
|
|
import { CN_CIDR_MISSING_IN_CHNROUTE, NON_CN_CIDR_INCLUDED_IN_CHNROUTE } from './constants/cidr';
|
|
import { CN_CIDR_MISSING_IN_CHNROUTE, NON_CN_CIDR_INCLUDED_IN_CHNROUTE } from './constants/cidr';
|
|
|
import { appendArrayInPlace } from './lib/append-array-in-place';
|
|
import { appendArrayInPlace } from './lib/append-array-in-place';
|
|
|
import { IPListOutput } from './lib/rules/ip';
|
|
import { IPListOutput } from './lib/rules/ip';
|
|
|
-import { cachedOnlyFail } from './lib/fs-memo';
|
|
|
|
|
import { createFileDescription } from './constants/description';
|
|
import { createFileDescription } from './constants/description';
|
|
|
|
|
|
|
|
const PROBE_CHN_CIDR_V4 = [
|
|
const PROBE_CHN_CIDR_V4 = [
|
|
@@ -16,34 +15,28 @@ const PROBE_CHN_CIDR_V4 = [
|
|
|
'120.78.92.171'
|
|
'120.78.92.171'
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
-export const getChnCidrPromise = createMemoizedPromise(cachedOnlyFail<[], [string[], string[]]>(
|
|
|
|
|
- async function getChnCidr() {
|
|
|
|
|
- const [_cidr4, cidr6] = await Promise.all([
|
|
|
|
|
- fetchRemoteTextByLine('https://raw.githubusercontent.com/misakaio/chnroutes2/master/chnroutes.txt', true).then(Array.fromAsync<string>),
|
|
|
|
|
- fetchRemoteTextByLine('https://gaoyifan.github.io/china-operator-ip/china6.txt', true).then(Array.fromAsync<string>)
|
|
|
|
|
- ]);
|
|
|
|
|
|
|
+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>),
|
|
|
|
|
+ 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
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ 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;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ 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;
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- serializer: JSON.stringify,
|
|
|
|
|
- deserializer: JSON.parse
|
|
|
|
|
}
|
|
}
|
|
|
-));
|
|
|
|
|
|
|
+
|
|
|
|
|
+ return [cidr4, cidr6] as const;
|
|
|
|
|
+});
|
|
|
|
|
|
|
|
export const buildChnCidr = task(require.main === module, __filename)(async (span) => {
|
|
export const buildChnCidr = task(require.main === module, __filename)(async (span) => {
|
|
|
const [filteredCidr4, cidr6] = await span.traceChildAsync('download chnroutes2', getChnCidrPromise);
|
|
const [filteredCidr4, cidr6] = await span.traceChildAsync('download chnroutes2', getChnCidrPromise);
|