mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-28 17:41:54 +08:00
Fix: an fetch option to allow remote upstream to be empty
https://feodotracker.abuse.ch/faq/
This commit is contained in:
@@ -43,7 +43,7 @@ const BOTNET_FILTER_MIRROR_URL = [
|
|||||||
// https://curbengh.github.io/malware-filter/botnet-filter-dnscrypt-blocked-ips.txt
|
// https://curbengh.github.io/malware-filter/botnet-filter-dnscrypt-blocked-ips.txt
|
||||||
];
|
];
|
||||||
|
|
||||||
const getBotNetFilterIPsPromise: Promise<[ipv4: string[], ipv6: string[]]> = fetchAssets(BOTNET_FILTER_URL, BOTNET_FILTER_MIRROR_URL, true).then(arr => arr.reduce<[ipv4: string[], ipv6: string[]]>((acc, ip) => {
|
const getBotNetFilterIPsPromise: Promise<[ipv4: string[], ipv6: string[]]> = fetchAssets(BOTNET_FILTER_URL, BOTNET_FILTER_MIRROR_URL, true, true).then(arr => arr.reduce<[ipv4: string[], ipv6: string[]]>((acc, ip) => {
|
||||||
const v = fastIpVersion(ip);
|
const v = fastIpVersion(ip);
|
||||||
if (v === 4) {
|
if (v === 4) {
|
||||||
acc[0].push(ip);
|
acc[0].push(ip);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
export const DEBUG_DOMAIN_TO_FIND: string | null = null; // example.com | null
|
export const DEBUG_DOMAIN_TO_FIND: string | null = null; // example.com | null
|
||||||
|
|
||||||
type HostsSource = [main: string, mirrors: string[] | null, includeAllSubDomain: boolean];
|
type HostsSource = [main: string, mirrors: string[] | null, includeAllSubDomain: boolean, allowEmptyRemote?: boolean];
|
||||||
|
|
||||||
export const HOSTS: HostsSource[] = [
|
export const HOSTS: HostsSource[] = [
|
||||||
// WindowsSpyBlocker hasn't been updated since 2022-06-16, its content has been merged into domainset/reject.conf
|
// WindowsSpyBlocker hasn't been updated since 2022-06-16, its content has been merged into domainset/reject.conf
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export class CustomAbortError extends Error {
|
|||||||
|
|
||||||
const reusedCustomAbortError = new CustomAbortError();
|
const reusedCustomAbortError = new CustomAbortError();
|
||||||
|
|
||||||
export async function fetchAssets(url: string, fallbackUrls: null | undefined | string[] | readonly string[], processLine = false) {
|
export async function fetchAssets(url: string, fallbackUrls: null | undefined | string[] | readonly string[], processLine = false, allowEmpty = false) {
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
|
|
||||||
const createFetchFallbackPromise = async (url: string, index: number) => {
|
const createFetchFallbackPromise = async (url: string, index: number) => {
|
||||||
@@ -38,7 +38,7 @@ export async function fetchAssets(url: string, fallbackUrls: null | undefined |
|
|||||||
}
|
}
|
||||||
const arr = await Array.fromAsync(stream);
|
const arr = await Array.fromAsync(stream);
|
||||||
|
|
||||||
if (arr.length < 1) {
|
if (arr.length < 1 && !allowEmpty) {
|
||||||
throw new ResponseError(res, url, 'empty response w/o 304');
|
throw new ResponseError(res, url, 'empty response w/o 304');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,9 +22,10 @@ function domainListLineCbIncludeAllSubdomain(line: string, set: string[], meta:
|
|||||||
}
|
}
|
||||||
export function processDomainListsWithPreload(
|
export function processDomainListsWithPreload(
|
||||||
domainListsUrl: string, mirrors: string[] | null,
|
domainListsUrl: string, mirrors: string[] | null,
|
||||||
includeAllSubDomain = false
|
includeAllSubDomain = false,
|
||||||
|
allowEmptyRemote = false
|
||||||
) {
|
) {
|
||||||
const downloadPromise = fetchAssets(domainListsUrl, mirrors, true);
|
const downloadPromise = fetchAssets(domainListsUrl, mirrors, true, allowEmptyRemote);
|
||||||
const lineCb = includeAllSubDomain ? domainListLineCbIncludeAllSubdomain : domainListLineCb;
|
const lineCb = includeAllSubDomain ? domainListLineCbIncludeAllSubdomain : domainListLineCb;
|
||||||
|
|
||||||
return (span: Span) => span.traceChildAsync(`process domainlist: ${domainListsUrl}`, async (span) => {
|
return (span: Span) => span.traceChildAsync(`process domainlist: ${domainListsUrl}`, async (span) => {
|
||||||
|
|||||||
@@ -56,8 +56,8 @@ export function processHosts(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function processHostsWithPreload(hostsUrl: string, mirrors: string[] | null, includeAllSubDomain = false) {
|
export function processHostsWithPreload(hostsUrl: string, mirrors: string[] | null, includeAllSubDomain = false, allowEmptyRemote = false) {
|
||||||
const downloadPromise = fetchAssets(hostsUrl, mirrors, true);
|
const downloadPromise = fetchAssets(hostsUrl, mirrors, true, allowEmptyRemote);
|
||||||
const cb = includeAllSubDomain ? hostsLineCbIncludeAllSubdomain : hostsLineCb;
|
const cb = includeAllSubDomain ? hostsLineCbIncludeAllSubdomain : hostsLineCb;
|
||||||
|
|
||||||
return (span: Span) => span.traceChildAsync(`process hosts: ${hostsUrl}`, async (span) => {
|
return (span: Span) => span.traceChildAsync(`process hosts: ${hostsUrl}`, async (span) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user