|
1 |
| -import { fastNormalizeDomain, fastNormalizeDomainWithoutWww } from '../normalize-domain'; |
| 1 | +import { fastNormalizeDomainWithoutWww } from '../normalize-domain'; |
2 | 2 | import { onBlackFound } from './shared';
|
3 | 3 | import { fetchAssets } from '../fetch-assets';
|
4 | 4 | import type { Span } from '../../trace';
|
5 | 5 |
|
6 |
| -function domainListLineCb(line: string, set: string[], meta: string, normalizeDomain = fastNormalizeDomain) { |
7 |
| - const domain = normalizeDomain(line); |
8 |
| - if (!domain) return; |
9 |
| - |
10 |
| - onBlackFound(domain, meta); |
11 |
| - |
12 |
| - set.push(domain); |
13 |
| -} |
14 |
| - |
15 |
| -function domainListLineCbIncludeAllSubdomain(line: string, set: string[], meta: string, normalizeDomain = fastNormalizeDomain) { |
16 |
| - const domain = normalizeDomain(line); |
17 |
| - if (!domain) return; |
18 |
| - |
19 |
| - onBlackFound(domain, meta); |
20 |
| - |
21 |
| - set.push('.' + domain); |
22 |
| -} |
23 | 6 | export function processDomainListsWithPreload(
|
24 | 7 | domainListsUrl: string, mirrors: string[] | null,
|
25 |
| - includeAllSubDomain = false |
| 8 | + _includeAllSubDomain = false |
26 | 9 | ) {
|
27 | 10 | const downloadPromise = fetchAssets(domainListsUrl, mirrors, true);
|
28 |
| - const lineCb = includeAllSubDomain ? domainListLineCbIncludeAllSubdomain : domainListLineCb; |
29 | 11 |
|
30 |
| - return (span: Span) => span.traceChildAsync(`process domainlist: ${domainListsUrl}`, async (span) => { |
| 12 | + return (span: Span, onDomain: (domain: string) => void) => span.traceChildAsync(`process domainlist: ${domainListsUrl}`, async (span) => { |
31 | 13 | const filterRules = await span.traceChildPromise('download', downloadPromise);
|
32 |
| - const domainSets: string[] = []; |
33 | 14 |
|
34 | 15 | span.traceChildSync('parse domain list', () => {
|
35 | 16 | for (let i = 0, len = filterRules.length; i < len; i++) {
|
36 |
| - lineCb(filterRules[i], domainSets, domainListsUrl, fastNormalizeDomainWithoutWww); |
| 17 | + const domain = fastNormalizeDomainWithoutWww(filterRules[i]); |
| 18 | + if (!domain) return; |
| 19 | + |
| 20 | + onBlackFound(domain, domainListsUrl); |
| 21 | + |
| 22 | + onDomain(domain); |
37 | 23 | }
|
38 | 24 | });
|
39 |
| - |
40 |
| - return domainSets; |
41 | 25 | });
|
42 | 26 | }
|
0 commit comments