This commit is contained in:
2026-05-09 17:15:23 +08:00
parent 80a4183b45
commit a0ed128bde
43 changed files with 2573 additions and 381 deletions

View File

@@ -1,4 +1,8 @@
import { ApiClientError, requestJson } from './apiClient';
import {
ApiClientError,
type ApiRequestOptions,
requestJson,
} from './apiClient';
export type AssetReadUrlRequest = {
objectKey?: string;
@@ -41,6 +45,11 @@ type CachedReadUrlFailureEntry = {
const ASSET_READ_URL_API_PATH = '/api/assets/read-url';
const DEFAULT_CACHE_SAFETY_WINDOW_MS = 30 * 1000;
const DEFAULT_FAILURE_CACHE_WINDOW_MS = 60 * 1000;
const ASSET_READ_URL_BACKGROUND_OPTIONS = {
skipRefresh: true,
notifyAuthStateChange: false,
clearAuthOnUnauthorized: false,
} satisfies ApiRequestOptions;
const signedReadUrlCache = new Map<string, CachedReadUrlEntry>();
const signedReadUrlFailureCache = new Map<string, CachedReadUrlFailureEntry>();
const pendingSignedReadUrlRequests = new Map<string, Promise<string>>();
@@ -165,6 +174,10 @@ export async function getSignedAssetReadUrl(
signal,
},
'获取资源访问地址失败',
{
// 中文注释:图片换签属于展示层后台请求,失败只影响当前图片,不应刷新或清空全局登录态。
...ASSET_READ_URL_BACKGROUND_OPTIONS,
},
);
const payload = resolveSignedReadPayload(response);
const expiresAtMs = parseExpiresAtMs(payload.expiresAt);