Refactor: minor simplifications

This commit is contained in:
SukkaW
2024-05-27 00:20:49 +08:00
parent e4429a62ee
commit 8b1eeb1c14
4 changed files with 45 additions and 42 deletions

View File

@@ -42,28 +42,30 @@ interface FetchRetryOpt {
retries?: number,
factor?: number,
maxRetryAfter?: number,
retry?: number,
onRetry?: (err: Error) => void,
retryOnAborted?: boolean
// onRetry?: (err: Error) => void,
retryOnAborted?: boolean,
retryOnNon2xx?: boolean
}
interface FetchWithRetry {
(url: string | URL | Request, opts?: RequestInit & { retry?: FetchRetryOpt }): Promise<Response>
}
const DEFAULT_OPT: Required<FetchRetryOpt> = {
// timeouts will be [10, 60, 360, 2160, 12960]
// (before randomization is added)
minTimeout: MIN_TIMEOUT,
retries: MAX_RETRIES,
factor: FACTOR,
maxRetryAfter: MAX_RETRY_AFTER,
retryOnAborted: false,
retryOnNon2xx: true
};
function createFetchRetry($fetch: typeof fetch): FetchWithRetry {
const fetchRetry: FetchWithRetry = async (url, opts = {}) => {
const retryOpts = Object.assign(
{
// timeouts will be [10, 60, 360, 2160, 12960]
// (before randomization is added)
minTimeout: MIN_TIMEOUT,
retries: MAX_RETRIES,
factor: FACTOR,
maxRetryAfter: MAX_RETRY_AFTER,
retryOnAborted: false,
retryOnNon2xx: true
},
DEFAULT_OPT,
opts.retry
);

View File

@@ -131,13 +131,11 @@ export const getPhishingDomains = (parentSpan: Span) => parentSpan.traceChild('g
}
});
span.traceChildSync('get final phishing results', () => {
for (const domain in domainCountMap) {
if (domainCountMap[domain] >= 8) {
domainArr.push(`.${domain}`);
}
for (const domain in domainCountMap) {
if (domainCountMap[domain] >= 8) {
domainArr.push(`.${domain}`);
}
});
}
return domainArr;
});

View File

@@ -78,7 +78,7 @@ export const PHISHING_DOMAIN_LISTS: [HostsSource, HostsSource] = [
]
] as const;
type AdGuardFilterSource = string | [main: string, mirrors: string[] | null, ttl: number];
type AdGuardFilterSource = [main: string, mirrors: string[] | null, ttl: number];
export const ADGUARD_FILTERS: AdGuardFilterSource[] = [
// EasyList