build-internal-reverse-chn-cidr.ts 754 B

1234567891011121314151617181920212223
  1. import path from 'path';
  2. import { task } from './trace';
  3. import { exclude, merge } from 'fast-cidr-tools';
  4. import { getChnCidrPromise } from './build-chn-cidr';
  5. import { NON_CN_CIDR_INCLUDED_IN_CHNROUTE, RESERVED_IPV4_CIDR } from './constants/cidr';
  6. export const buildInternalReverseChnCIDR = task(import.meta.main, import.meta.path)(async () => {
  7. const cidr = await getChnCidrPromise();
  8. const reversedCidr = merge(
  9. exclude(
  10. ['0.0.0.0/0'],
  11. RESERVED_IPV4_CIDR.concat(cidr),
  12. true
  13. ).concat(
  14. // https://github.com/misakaio/chnroutes2/issues/25
  15. NON_CN_CIDR_INCLUDED_IN_CHNROUTE
  16. )
  17. );
  18. return Bun.write(path.resolve(import.meta.dir, '../Internal/reversed-chn-cidr.txt'), `${reversedCidr.join('\n')}\n`);
  19. });