mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Refactor: use retry from undici
This commit is contained in:
@@ -8,9 +8,11 @@ import { fastStringArrayJoin, identity, mergeHeaders } from './misc';
|
||||
import { performance } from 'node:perf_hooks';
|
||||
import fs from 'node:fs';
|
||||
import { stringHash } from './string-hash';
|
||||
import { defaultRequestInit, fetchWithRetry } from './fetch-retry';
|
||||
import { defaultRequestInit, fetchWithLog } from './fetch-retry';
|
||||
import { Custom304NotModifiedError, CustomAbortError, CustomNoETagFallbackError, fetchAssets, sleepWithAbort } from './fetch-assets';
|
||||
|
||||
import type { Response, RequestInit } from 'undici';
|
||||
|
||||
const enum CacheStatus {
|
||||
Hit = 'hit',
|
||||
Stale = 'stale',
|
||||
@@ -216,7 +218,7 @@ export class Cache<S = string> {
|
||||
requestInit?: RequestInit
|
||||
): Promise<T> {
|
||||
if (opt.temporaryBypass) {
|
||||
return fn(await fetchWithRetry(url, requestInit ?? defaultRequestInit));
|
||||
return fn(await fetchWithLog(url, requestInit));
|
||||
}
|
||||
|
||||
const baseKey = url + '$' + extraCacheKey;
|
||||
@@ -255,10 +257,10 @@ export class Cache<S = string> {
|
||||
|
||||
const cached = this.get(cachedKey);
|
||||
if (cached == null) {
|
||||
return onMiss(await fetchWithRetry(url, requestInit ?? defaultRequestInit));
|
||||
return onMiss(await fetchWithLog(url, requestInit));
|
||||
}
|
||||
|
||||
const resp = await fetchWithRetry(
|
||||
const resp = await fetchWithLog(
|
||||
url,
|
||||
{
|
||||
...(requestInit ?? defaultRequestInit),
|
||||
@@ -321,7 +323,7 @@ export class Cache<S = string> {
|
||||
}
|
||||
|
||||
const etag = this.get(getETagKey(url));
|
||||
const res = await fetchWithRetry(
|
||||
const res = await fetchWithLog(
|
||||
url,
|
||||
{
|
||||
signal: controller.signal,
|
||||
|
||||
Reference in New Issue
Block a user