mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 01:00:34 +08:00
Remove tldts cache
This commit is contained in:
parent
dc21691ce6
commit
333e2054d9
@ -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);
|
||||||
|
|||||||
@ -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;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user