download-publicsuffixlist.ts 837 B

123456789101112131415161718
  1. import { TTL, fsFetchCache } from './lib/cache-filesystem';
  2. import { defaultRequestInit, fetchWithRetry } from './lib/fetch-retry';
  3. import { createMemoizedPromise } from './lib/memo-promise';
  4. import { traceAsync } from './lib/trace-runner';
  5. export const getPublicSuffixListTextPromise = createMemoizedPromise(() => traceAsync(
  6. 'obtain public_suffix_list',
  7. () => fsFetchCache.apply(
  8. 'https://publicsuffix.org/list/public_suffix_list.dat',
  9. () => fetchWithRetry('https://publicsuffix.org/list/public_suffix_list.dat', defaultRequestInit).then(r => r.text()),
  10. {
  11. // https://github.com/publicsuffix/list/blob/master/.github/workflows/tld-update.yml
  12. // Though the action runs every 24 hours, the IANA list is updated every 7 days.
  13. // So a 3 day TTL should be enough.
  14. ttl: TTL.THREE_DAYS()
  15. }
  16. )
  17. ));