轮询修改,媒体过期判断
This commit is contained in:
@@ -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 }),
|
||||
|
||||
Reference in New Issue
Block a user