mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Refactor: simplify more validation tools
This commit is contained in:
@@ -35,39 +35,19 @@ function onDomain(args: [string, boolean]) {
|
|||||||
.withPromise();
|
.withPromise();
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
...domainSets.map(runAgainstDomainset),
|
...domainRules,
|
||||||
...domainRules.map(runAgainstRuleset)
|
...domainSets
|
||||||
]);
|
].map(filepath => runAgainstSourceFile(
|
||||||
|
filepath,
|
||||||
|
(domain: string, includeAllSubdomain: boolean) => queue.add(
|
||||||
|
() => keyedAsyncMutexWithQueue(
|
||||||
|
domain,
|
||||||
|
() => isDomainAlive(domain, includeAllSubdomain)
|
||||||
|
).then(onDomain)
|
||||||
|
).then(() => console.log('[done]', filepath))
|
||||||
|
)));
|
||||||
|
|
||||||
console.log();
|
console.log();
|
||||||
console.log();
|
console.log();
|
||||||
console.log(JSON.stringify(deadDomains));
|
console.log(JSON.stringify(deadDomains));
|
||||||
})();
|
})();
|
||||||
|
|
||||||
export async function runAgainstRuleset(filepath: string) {
|
|
||||||
const promises: Array<Promise<void>> = [];
|
|
||||||
await runAgainstSourceFile(
|
|
||||||
filepath,
|
|
||||||
(domain: string, includeAllSubdomain: boolean) => queue.add(() => keyedAsyncMutexWithQueue(
|
|
||||||
domain,
|
|
||||||
() => isDomainAlive(domain, includeAllSubdomain)
|
|
||||||
).then(onDomain))
|
|
||||||
);
|
|
||||||
|
|
||||||
await Promise.all(promises);
|
|
||||||
console.log('[done]', filepath);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function runAgainstDomainset(filepath: string) {
|
|
||||||
const promises: Array<Promise<void>> = [];
|
|
||||||
|
|
||||||
await runAgainstSourceFile(
|
|
||||||
filepath,
|
|
||||||
(domain: string, includeAllSubdomain: boolean) => queue.add(() => keyedAsyncMutexWithQueue(
|
|
||||||
domain,
|
|
||||||
() => isDomainAlive(domain, includeAllSubdomain)
|
|
||||||
).then(onDomain))
|
|
||||||
);
|
|
||||||
await Promise.all(promises);
|
|
||||||
console.log('[done]', filepath);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -5,8 +5,31 @@ import { loosTldOptWithPrivateDomains } from './constants/loose-tldts-opt';
|
|||||||
import runAgainstSourceFile from './lib/run-against-source-file';
|
import runAgainstSourceFile from './lib/run-against-source-file';
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const rejectDomainCountMap = await runAgainstDomainset(new Map<string, number>(), path.join(OUTPUT_SURGE_DIR, 'domainset', 'reject.conf'));
|
const rejectDomainCountMap = new Map<string, number>();
|
||||||
const rejectExtraDomainCountMap = await runAgainstDomainset(new Map<string, number>(), path.join(OUTPUT_SURGE_DIR, 'domainset', 'reject_extra.conf'));
|
const rejectExtraDomainCountMap = new Map<string, number>();
|
||||||
|
|
||||||
|
const callback = (map: Map<string, number>) => (domain: string) => {
|
||||||
|
const apexDomain = tldts.getDomain(domain, loosTldOptWithPrivateDomains);
|
||||||
|
if (!apexDomain) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
map.set(
|
||||||
|
apexDomain,
|
||||||
|
rejectDomainCountMap.has(apexDomain)
|
||||||
|
? rejectDomainCountMap.get(apexDomain)! + 1
|
||||||
|
: 1
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
await runAgainstSourceFile(
|
||||||
|
path.join(OUTPUT_SURGE_DIR, 'domainset', 'reject.conf'),
|
||||||
|
callback(rejectDomainCountMap)
|
||||||
|
);
|
||||||
|
await runAgainstSourceFile(
|
||||||
|
path.join(OUTPUT_SURGE_DIR, 'domainset', 'reject_extra.conf'),
|
||||||
|
callback(rejectExtraDomainCountMap)
|
||||||
|
);
|
||||||
|
|
||||||
const rejectDomainCountArr = Array.from(rejectDomainCountMap).sort((a, b) => b[1] - a[1]).filter(([, count]) => count > 20);
|
const rejectDomainCountArr = Array.from(rejectDomainCountMap).sort((a, b) => b[1] - a[1]).filter(([, count]) => count > 20);
|
||||||
const rejectExtraDomainCountArr = Array.from(rejectExtraDomainCountMap).sort((a, b) => b[1] - a[1]).filter(([, count]) => count > 20);
|
const rejectExtraDomainCountArr = Array.from(rejectExtraDomainCountMap).sort((a, b) => b[1] - a[1]).filter(([, count]) => count > 20);
|
||||||
@@ -14,24 +37,3 @@ import runAgainstSourceFile from './lib/run-against-source-file';
|
|||||||
console.table(rejectDomainCountArr);
|
console.table(rejectDomainCountArr);
|
||||||
console.table(rejectExtraDomainCountArr);
|
console.table(rejectExtraDomainCountArr);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
async function runAgainstDomainset(rejectDomainCountMap: Map<string, number>, file: string) {
|
|
||||||
await runAgainstSourceFile(
|
|
||||||
file,
|
|
||||||
(domain: string) => {
|
|
||||||
const apexDomain = tldts.getDomain(domain, loosTldOptWithPrivateDomains);
|
|
||||||
if (!apexDomain) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
rejectDomainCountMap.set(
|
|
||||||
apexDomain,
|
|
||||||
rejectDomainCountMap.has(apexDomain)
|
|
||||||
? rejectDomainCountMap.get(apexDomain)! + 1
|
|
||||||
: 1
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return rejectDomainCountMap;
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user