validate-domain-alive.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. const promises: Array<Promise<void>> = [];
  34. await Promise.all([
  35. ...domainRules,
  36. ...domainSets
  37. ].map(
  38. filepath => runAgainstSourceFile(
  39. filepath,
  40. (domain: string, includeAllSubdomain: boolean) => promises.push(queue.add(
  41. () => keyedAsyncMutexWithQueue(
  42. domain,
  43. () => isDomainAlive(domain, includeAllSubdomain)
  44. ).then(onDomain)
  45. ))
  46. ).then(() => console.log('[crawl]', filepath))
  47. ));
  48. await Promise.all(promises);
  49. console.log();
  50. console.log();
  51. console.log(JSON.stringify(deadDomains));
  52. })();