Fix: an fetch option to allow remote upstream to be empty

https://feodotracker.abuse.ch/faq/
This commit is contained in:
SukkaW
2025-06-15 21:36:47 +08:00
parent 56276d5711
commit d5c13b06bd
5 changed files with 9 additions and 8 deletions

View File

@@ -13,7 +13,7 @@ export class CustomAbortError extends Error {
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 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);
if (arr.length < 1) {
if (arr.length < 1 && !allowEmpty) {
throw new ResponseError(res, url, 'empty response w/o 304');
}

View File

@@ -22,9 +22,10 @@ function domainListLineCbIncludeAllSubdomain(line: string, set: string[], meta:
}
export function processDomainListsWithPreload(
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;
return (span: Span) => span.traceChildAsync(`process domainlist: ${domainListsUrl}`, async (span) => {

View File

@@ -56,8 +56,8 @@ export function processHosts(
});
}
export function processHostsWithPreload(hostsUrl: string, mirrors: string[] | null, includeAllSubDomain = false) {
const downloadPromise = fetchAssets(hostsUrl, mirrors, true);
export function processHostsWithPreload(hostsUrl: string, mirrors: string[] | null, includeAllSubDomain = false, allowEmptyRemote = false) {
const downloadPromise = fetchAssets(hostsUrl, mirrors, true, allowEmptyRemote);
const cb = includeAllSubDomain ? hostsLineCbIncludeAllSubdomain : hostsLineCb;
return (span: Span) => span.traceChildAsync(`process hosts: ${hostsUrl}`, async (span) => {