mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Refactor: minor simplifications
This commit is contained in:
@@ -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
|
||||
);
|
||||
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user