build-apple-cdn.js 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. const { fetch } = require('undici');
  2. const fs = require('fs');
  3. const path = require('path');
  4. const rDomain = /^(((?!\-))(xn\-\-)?[a-z0-9\-_]{0,61}[a-z0-9]{1,1}\.)*(xn\-\-)?([a-z0-9\-]{1,61}|[a-z0-9\-]{1,30})\.[a-z]{2,}$/m;
  5. (async () => {
  6. const res = (await (await fetch('https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/apple.china.conf')).text())
  7. .split('\n')
  8. .map(line => {
  9. if (line.startsWith('server=/') && line.endsWith('/114.114.114.114')) {
  10. return line.replace('server=/', '').replace('/114.114.114.114', '');
  11. }
  12. return null
  13. })
  14. .filter(domain => typeof domain === 'string' && rDomain.test(domain));
  15. await Promise.all([
  16. fs.promises.writeFile(
  17. path.resolve(__dirname, '../List/non_ip/apple_cdn.conf'),
  18. res.map(domain => `DOMAIN,${domain}`).join('\n') + '\n',
  19. 'utf-8'
  20. ),
  21. fs.promises.writeFile(
  22. path.resolve(__dirname, '../List/domainset/apple_cdn.conf'),
  23. res.join('\n') + '\n',
  24. 'utf-8'
  25. )
  26. ])
  27. })();