download-publicsuffixlist.ts 915 B

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