_get-lum-apex-domains.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { fetchRemoteTextByLine, readFileByLine } from './lib/fetch-text-by-line';
  2. import tldts from 'tldts';
  3. import { HostnameSmolTrie } from './lib/trie';
  4. import path from 'node:path';
  5. import { SOURCE_DIR } from './constants/dir';
  6. import { processLine } from './lib/process-line';
  7. (async () => {
  8. const lines1 = await Array.fromAsync(await fetchRemoteTextByLine('https://raw.githubusercontent.com/durablenapkin/block/master/luminati.txt', true));
  9. const lines2 = await Array.fromAsync(await fetchRemoteTextByLine('https://raw.githubusercontent.com/durablenapkin/block/master/tvstream.txt', true));
  10. const trie = new HostnameSmolTrie();
  11. lines1.forEach((line) => {
  12. const apexDomain = tldts.getDomain(line.slice(8));
  13. if (apexDomain) {
  14. trie.add(apexDomain);
  15. }
  16. });
  17. lines2.forEach((line) => {
  18. const apexDomain = tldts.getDomain(line.slice(8));
  19. if (apexDomain) {
  20. trie.add(apexDomain);
  21. }
  22. });
  23. for await (const line of readFileByLine(path.join(SOURCE_DIR, 'domainset', 'reject.conf'))) {
  24. const l = processLine(line);
  25. if (l) {
  26. trie.whitelist(l);
  27. }
  28. }
  29. console.log(trie.dump().join('\n'));
  30. })();