validate-domain-alive.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { SOURCE_DIR } from './constants/dir';
  2. import path from 'node:path';
  3. import { newQueue } from '@henrygd/queue';
  4. import { isDomainAlive, keyedAsyncMutexWithQueue } from './lib/is-domain-alive';
  5. import { fdir as Fdir } from 'fdir';
  6. import runAgainstSourceFile from './lib/run-against-source-file';
  7. const queue = newQueue(24);
  8. const deadDomains: string[] = [];
  9. function onDomain(args: [string, boolean]) {
  10. if (!args[1]) {
  11. deadDomains.push(args[0]);
  12. }
  13. }
  14. (async () => {
  15. const domainSets = await new Fdir()
  16. .withFullPaths()
  17. .filter((filePath, isDirectory) => {
  18. if (isDirectory) return false;
  19. const extname = path.extname(filePath);
  20. return extname === '.txt' || extname === '.conf';
  21. })
  22. .crawl(SOURCE_DIR + path.sep + 'domainset')
  23. .withPromise();
  24. const domainRules = await new Fdir()
  25. .withFullPaths()
  26. .filter((filePath, isDirectory) => {
  27. if (isDirectory) return false;
  28. const extname = path.extname(filePath);
  29. return extname === '.txt' || extname === '.conf';
  30. })
  31. .crawl(SOURCE_DIR + path.sep + 'non_ip')
  32. .withPromise();
  33. await Promise.all([
  34. ...domainRules,
  35. ...domainSets
  36. ].map(filepath => runAgainstSourceFile(
  37. filepath,
  38. (domain: string, includeAllSubdomain: boolean) => queue.add(
  39. () => keyedAsyncMutexWithQueue(
  40. domain,
  41. () => isDomainAlive(domain, includeAllSubdomain)
  42. ).then(onDomain)
  43. ).then(() => console.log('[done]', filepath))
  44. )));
  45. console.log();
  46. console.log();
  47. console.log(JSON.stringify(deadDomains));
  48. })();