修复模型库空请求体删除失败

This commit is contained in:
zhangshun
2026-06-01 09:50:52 +08:00
parent 3dfed3a2df
commit fcec4f3db4

View File

@@ -6,10 +6,11 @@ function authHeaders(): Record<string, string> {
} }
export async function api<T>(url: string, options: RequestInit = {}): Promise<T> { export async function api<T>(url: string, options: RequestInit = {}): Promise<T> {
const hasBody = options.body !== undefined && options.body !== null;
const response = await fetch(url, { const response = await fetch(url, {
...options, ...options,
headers: { headers: {
...(options.body instanceof FormData ? {} : { "Content-Type": "application/json" }), ...(hasBody && !(options.body instanceof FormData) ? { "Content-Type": "application/json" } : {}),
...authHeaders(), ...authHeaders(),
...((options.headers as Record<string, string> | undefined) ?? {}) ...((options.headers as Record<string, string> | undefined) ?? {})
} as HeadersInit } as HeadersInit
@@ -20,4 +21,3 @@ export async function api<T>(url: string, options: RequestInit = {}): Promise<T>
} }
return data as T; return data as T;
} }