Remove tldts cache

This commit is contained in:
SukkaW 2024-01-15 16:24:41 +08:00
parent dc21691ce6
commit 333e2054d9
2 changed files with 2 additions and 15 deletions

View File

@ -1,19 +1,6 @@
import * as tldts from 'tldts';
import { createCache } from './cache-apply'; import { createCache } from './cache-apply';
import type { PublicSuffixList } from '@gorhill/publicsuffixlist'; import type { PublicSuffixList } from '@gorhill/publicsuffixlist';
const cache = createCache('cached-tld-parse', true);
const cache2 = createCache('cached-tld-parse2', true);
const sharedConfig = { allowPrivateDomains: true };
const sharedConfig2 = { allowPrivateDomains: true, detectIp: false };
/** { allowPrivateDomains: true } */
export const parse = (domain: string) => cache.sync(domain, () => tldts.parse(domain, sharedConfig));
/** { allowPrivateDomains: true, detectIp: false } */
export const parse2 = (domain: string) => cache2.sync(domain, () => tldts.parse(domain, sharedConfig2));
export const parseWithoutDetectIp = parse2;
let gothillGetDomainCache: ReturnType<typeof createCache> | null = null; let gothillGetDomainCache: ReturnType<typeof createCache> | null = null;
export const createCachedGorhillGetDomain = (gorhill: PublicSuffixList) => { export const createCachedGorhillGetDomain = (gorhill: PublicSuffixList) => {
gothillGetDomainCache ??= createCache('cached-gorhill-get-domain', true); gothillGetDomainCache ??= createCache('cached-gorhill-get-domain', true);

View File

@ -1,10 +1,10 @@
import * as tldts from './cached-tld-parse'; import * as tldts from 'tldts';
import { isProbablyIpv4 } from './is-fast-ip'; import { isProbablyIpv4 } from './is-fast-ip';
export const normalizeDomain = (domain: string) => { export const normalizeDomain = (domain: string) => {
if (!domain) return null; if (!domain) return null;
if (isProbablyIpv4(domain)) return null; if (isProbablyIpv4(domain)) return null;
const parsed = tldts.parse2(domain); const parsed = tldts.parse(domain, { allowPrivateDomains: true, detectIp: false });
// if (parsed.isIp) return null; // if (parsed.isIp) return null;
if (!parsed.hostname) return null; if (!parsed.hostname) return null;
if (!parsed.isIcann && !parsed.isPrivate) return null; if (!parsed.isIcann && !parsed.isPrivate) return null;