build-apple-cdn.js 853 B

123456789101112131415161718192021222324
  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 fs.promises.writeFile(
  16. path.resolve(__dirname, '../List/non_ip/apple_cdn.conf'),
  17. res.map(domain => `DOMAIN,${domain}`).join('\n') + '\n',
  18. 'utf-8'
  19. );
  20. })();