mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-28 17:41:54 +08:00
Feat: implement parallel fetch w/ HTTP 304 (#43)
This commit is contained in:
@@ -4,14 +4,11 @@ import { createReadlineInterfaceFromResponse, readFileIntoProcessedArray } from
|
||||
import { task } from './trace';
|
||||
import { SHARED_DESCRIPTION } from './lib/constants';
|
||||
import { isProbablyIpv4, isProbablyIpv6 } from './lib/is-fast-ip';
|
||||
import { TTL, fsFetchCache, createCacheKey, getFileContentHash } from './lib/cache-filesystem';
|
||||
import { fetchAssets } from './lib/fetch-assets';
|
||||
import { fsFetchCache, getFileContentHash } from './lib/cache-filesystem';
|
||||
import { processLine } from './lib/process-line';
|
||||
import { RulesetOutput } from './lib/create-file';
|
||||
import { SOURCE_DIR } from './constants/dir';
|
||||
|
||||
const cacheKey = createCacheKey(__filename);
|
||||
|
||||
const BOGUS_NXDOMAIN_URL = 'https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/bogus-nxdomain.china.conf';
|
||||
|
||||
const getBogusNxDomainIPsPromise = fsFetchCache.applyWithHttp304(
|
||||
@@ -39,31 +36,31 @@ const getBogusNxDomainIPsPromise = fsFetchCache.applyWithHttp304(
|
||||
}
|
||||
);
|
||||
|
||||
const BOTNET_FILTER_URL = 'https://curbengh.github.io/botnet-filter/botnet-filter-dnscrypt-blocked-ips.txt';
|
||||
const BOTNET_FILTER_URL = 'https://malware-filter.pages.dev/botnet-filter-dnscrypt-blocked-ips.txt';
|
||||
const BOTNET_FILTER_MIRROR_URL = [
|
||||
'https://curbengh.github.io/malware-filter/botnet-filter-dnscrypt-blocked-ips.txt',
|
||||
'https://botnet-filter.pages.dev/botnet-filter-dnscrypt-blocked-ips.txt',
|
||||
'https://malware-filter.gitlab.io/malware-filter/botnet-filter-dnscrypt-blocked-ips.txt',
|
||||
'https://malware-filter.pages.dev/botnet-filter-dnscrypt-blocked-ips.txt'
|
||||
'https://malware-filter.gitlab.io/botnet-filter/botnet-filter-dnscrypt-blocked-ips.txt'
|
||||
// 'https://curbengh.github.io/botnet-filter/botnet-filter-dnscrypt-blocked-ips.txt',
|
||||
// https://curbengh.github.io/malware-filter/botnet-filter-dnscrypt-blocked-ips.txt
|
||||
];
|
||||
|
||||
const getBotNetFilterIPsPromise = fsFetchCache.apply<[ipv4: string[], ipv6: string[]]>(
|
||||
cacheKey(BOTNET_FILTER_URL),
|
||||
async () => {
|
||||
const text = await fetchAssets(BOTNET_FILTER_URL, BOTNET_FILTER_MIRROR_URL);
|
||||
return text.split('\n').reduce<[ipv4: string[], ipv6: string[]]>((acc, cur) => {
|
||||
const ip = processLine(cur);
|
||||
if (ip) {
|
||||
if (isProbablyIpv4(ip)) {
|
||||
acc[0].push(ip);
|
||||
} else if (isProbablyIpv6(ip)) {
|
||||
acc[1].push(ip);
|
||||
}
|
||||
const getBotNetFilterIPsPromise = fsFetchCache.applyWithHttp304AndMirrors<[ipv4: string[], ipv6: string[]]>(
|
||||
BOTNET_FILTER_URL,
|
||||
BOTNET_FILTER_MIRROR_URL,
|
||||
getFileContentHash(__filename),
|
||||
(text) => text.split('\n').reduce<[ipv4: string[], ipv6: string[]]>((acc, cur) => {
|
||||
const ip = processLine(cur);
|
||||
if (ip) {
|
||||
if (isProbablyIpv4(ip)) {
|
||||
acc[0].push(ip);
|
||||
} else if (isProbablyIpv6(ip)) {
|
||||
acc[1].push(ip);
|
||||
}
|
||||
return acc;
|
||||
}, [[], []]);
|
||||
},
|
||||
}
|
||||
return acc;
|
||||
}, [[], []]),
|
||||
{
|
||||
ttl: TTL.TWLVE_HOURS(),
|
||||
serializer: JSON.stringify,
|
||||
deserializer: JSON.parse
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user