轮询修改,媒体过期判断

This commit is contained in:
孙佳艺
2026-06-04 13:03:04 +08:00
parent 64f7069ae2
commit 450e509b1a
13 changed files with 1812 additions and 678 deletions
+7 -2
View File
@@ -13,6 +13,7 @@ interface RequestOptions {
body?: unknown;
auth?: boolean;
encryptBody?: boolean;
signal?: AbortSignal;
}
/** Convert snake_case string to camelCase */
@@ -53,7 +54,7 @@ async function tryDecrypt(data: string): Promise<string | null> {
}
export async function apiRequest<T>(path: string, options: RequestOptions = {}): Promise<T> {
const { method = 'GET', body, auth = true, encryptBody = USE_ENCRYPTION } = options;
const { method = 'GET', body, auth = true, encryptBody = USE_ENCRYPTION, signal } = options;
const headers: Record<string, string> = {
'Content-Type': 'application/json',
@@ -79,6 +80,7 @@ export async function apiRequest<T>(path: string, options: RequestOptions = {}):
method,
headers,
body: bodyStr,
signal,
});
if (res.status === 204) return undefined as T;
@@ -120,7 +122,10 @@ if (!res.ok) {
// Convenience methods
export const api = {
get: <T>(path: string, auth = true) => apiRequest<T>(path, { auth }),
get: <T>(path: string, options: boolean | { auth?: boolean; signal?: AbortSignal } = true) => {
const opts = typeof options === 'boolean' ? { auth: options } : options;
return apiRequest<T>(path, opts);
},
post: <T>(path: string, body?: unknown, auth = true) => apiRequest<T>(path, { method: 'POST', body, auth }),
put: <T>(path: string, body?: unknown, auth = true) => apiRequest<T>(path, { method: 'PUT', body, auth }),
delete: <T>(path: string, auth = true) => apiRequest<T>(path, { method: 'DELETE', auth }),