Update Reject Hosts

This commit is contained in:
SukkaW
2024-03-25 14:05:37 +08:00
parent 45145958b2
commit fc0bfdc9a0
5 changed files with 43 additions and 42 deletions

View File

@@ -114,14 +114,11 @@ export const buildRejectDomainSet = task(import.meta.path, async (span) => {
});
filterRuleWhitelistDomainSets.forEach(suffix => {
trie.substractSetInPlaceFromFound(suffix, domainSets);
if (suffix[0] === '.') {
// handle case like removing `g.msn.com` due to white `.g.msn.com` (`@@||g.msn.com`)
domainSets.delete(suffix.slice(1));
} else {
// If `g.msn.com` is whitelisted, then `.g.msn.com` should be removed from domain set
domainSets.delete(`.${suffix}`);
}
domainSets.delete(
suffix[0] === '.'
? suffix.slice(1) // handle case like removing `g.msn.com` due to white `.g.msn.com` (`@@||g.msn.com`)
: `.${suffix}` // If `g.msn.com` is whitelisted, then `.g.msn.com` should be removed from domain set
);
});
});

View File

@@ -65,7 +65,7 @@ export const downloadPreviousBuild = task(import.meta.path, async (span) => {
const extract = tarStream.extract();
pipeline(
Readable.fromWeb(resp.body as unknown as import('stream/web').ReadableStream<any>),
Readable.fromWeb(resp.body as any),
gunzip,
extract
);

View File

@@ -29,9 +29,9 @@ import { buildCloudMounterRules } from './build-cloudmounter-rules';
import { createSpan, printTraceResult } from './trace';
import { buildDeprecateFiles } from './build-deprecate-files';
(async () => {
console.log('Bun version:', Bun.version, Bun.revision);
console.log('Bun version:', Bun.version, Bun.revision);
(async () => {
const rootSpan = createSpan('root');
try {

View File

@@ -47,33 +47,33 @@ export function processDomainLists(span: Span, domainListsUrl: string, includeAl
));
}
export function processHosts(span: Span, hostsUrl: string, mirrors: string[] | null, includeAllSubDomain = false, ttl: number | null = null) {
const domainSets = new Set<string>();
const lineCb = (l: string) => {
const line = processLine(l);
if (!line) {
return;
}
const _domain = line.split(/\s/)[1]?.trim();
if (!_domain) {
return;
}
const domain = normalizeDomain(_domain);
if (!domain) {
return;
}
if (DEBUG_DOMAIN_TO_FIND && domain.includes(DEBUG_DOMAIN_TO_FIND)) {
console.warn(picocolors.red(hostsUrl), '(black)', domain.replaceAll(DEBUG_DOMAIN_TO_FIND, picocolors.bold(DEBUG_DOMAIN_TO_FIND)));
foundDebugDomain = true;
}
domainSets.add(includeAllSubDomain ? `.${domain}` : domain);
};
return span.traceChild(`processhosts: ${hostsUrl}`).traceAsyncFn((childSpan) => fsFetchCache.apply(
hostsUrl,
async () => {
const domainSets = new Set<string>();
const lineCb = (l: string) => {
const line = processLine(l);
if (!line) {
return;
}
const _domain = line.split(/\s/)[1]?.trim();
if (!_domain) {
return;
}
const domain = normalizeDomain(_domain);
if (!domain) {
return;
}
if (DEBUG_DOMAIN_TO_FIND && domain.includes(DEBUG_DOMAIN_TO_FIND)) {
console.warn(picocolors.red(hostsUrl), '(black)', domain.replaceAll(DEBUG_DOMAIN_TO_FIND, picocolors.bold(DEBUG_DOMAIN_TO_FIND)));
foundDebugDomain = true;
}
domainSets.add(includeAllSubDomain ? `.${domain}` : domain);
};
if (mirrors == null || mirrors.length === 0) {
for await (const l of await fetchRemoteTextByLine(hostsUrl)) {
lineCb(l);