mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-28 17:41:54 +08:00
Refactor: fetch directly
This commit is contained in:
@@ -4,11 +4,11 @@ import { createReadlineInterfaceFromResponse, readFileIntoProcessedArray } from
|
||||
import { task } from './trace';
|
||||
import { SHARED_DESCRIPTION } from './constants/description';
|
||||
import { isProbablyIpv4, isProbablyIpv6 } from 'foxts/is-probably-ip';
|
||||
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';
|
||||
import { $$fetch } from './lib/fetch-retry';
|
||||
import { fetchAssetsWithout304 } from './lib/fetch-assets';
|
||||
|
||||
const BOGUS_NXDOMAIN_URL = 'https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/bogus-nxdomain.china.conf';
|
||||
const getBogusNxDomainIPsPromise: Promise<[ipv4: string[], ipv6: string[]]> = $$fetch(BOGUS_NXDOMAIN_URL).then(async (resp) => {
|
||||
@@ -37,26 +37,17 @@ const BOTNET_FILTER_MIRROR_URL = [
|
||||
// https://curbengh.github.io/malware-filter/botnet-filter-dnscrypt-blocked-ips.txt
|
||||
];
|
||||
|
||||
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);
|
||||
}
|
||||
const getBotNetFilterIPsPromise: Promise<[ipv4: string[], ipv6: string[]]> = fetchAssetsWithout304(BOTNET_FILTER_URL, BOTNET_FILTER_MIRROR_URL).then(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;
|
||||
}, [[], []]),
|
||||
{
|
||||
serializer: JSON.stringify,
|
||||
deserializer: JSON.parse
|
||||
}
|
||||
);
|
||||
return acc;
|
||||
}, [[], []]));
|
||||
|
||||
export const buildRejectIPList = task(require.main === module, __filename)(async (span) => {
|
||||
const [bogusNxDomainIPs, botNetIPs] = await Promise.all([
|
||||
|
||||
Reference in New Issue
Block a user