build-apple-cdn.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. const { fetchWithRetry } = require('./lib/fetch-retry');
  2. const fs = require('fs');
  3. const path = require('path');
  4. const { isDomainLoose } = require('./lib/is-domain-loose');
  5. const { compareAndWriteFile } = require('./lib/string-array-compare');
  6. const { withBannerArray } = require('./lib/with-banner');
  7. (async () => {
  8. console.time('Total Time - build-apple-cdn-conf');
  9. const res = (await (await fetchWithRetry('https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/apple.china.conf')).text())
  10. .split('\n')
  11. .map(line => {
  12. if (line.startsWith('server=/') && line.endsWith('/114.114.114.114')) {
  13. return line.replace('server=/', '').replace('/114.114.114.114', '');
  14. }
  15. return null
  16. })
  17. .filter(domain => typeof domain === 'string' && isDomainLoose(domain));
  18. await Promise.all([
  19. compareAndWriteFile(
  20. withBannerArray(
  21. 'Sukka\'s Surge Rules - Apple CDN',
  22. [
  23. 'License: AGPL 3.0',
  24. 'Homepage: https://ruleset.skk.moe',
  25. 'GitHub: https://github.com/SukkaW/Surge',
  26. '',
  27. 'This file contains Apple\'s domains using their China mainland CDN servers.',
  28. '',
  29. 'Data from:',
  30. ' - https://github.com/felixonmars/dnsmasq-china-list',
  31. ],
  32. new Date(),
  33. res.map(domain => `DOMAIN-SUFFIX,${domain}`)
  34. ),
  35. path.resolve(__dirname, '../List/non_ip/apple_cdn.conf')
  36. ),
  37. compareAndWriteFile(
  38. withBannerArray(
  39. 'Sukka\'s Surge Rules - Apple CDN',
  40. [
  41. 'License: AGPL 3.0',
  42. 'Homepage: https://ruleset.skk.moe',
  43. 'GitHub: https://github.com/SukkaW/Surge',
  44. '',
  45. 'This file contains Apple\'s domains using their China mainland CDN servers.',
  46. '',
  47. 'Data from:',
  48. ' - https://github.com/felixonmars/dnsmasq-china-list',
  49. ],
  50. new Date(),
  51. res.map(i => `.${i}`)
  52. ),
  53. path.resolve(__dirname, '../List/domainset/apple_cdn.conf')
  54. )
  55. ])
  56. console.timeEnd('Total Time - build-apple-cdn-conf');
  57. })();