fix: preserve data granularity and recover tasks safely

This commit is contained in:
Codex
2026-10-11 14:18:56 +08:00
parent 23f3a15a15
commit 603184549b
29 changed files with 4557 additions and 418 deletions
+21 -5
View File
@@ -1,9 +1,25 @@
export async function api<T>(path: string, options: RequestInit = {}): Promise<T> {
const response = await fetch('/api' + path, { ...options, headers: options.body instanceof FormData ? options.headers : { 'Content-Type': 'application/json', ...options.headers } });
export async function api<T>(
path: string,
options: RequestInit = {},
): Promise<T> {
const response = await fetch("/api" + path, {
...options,
headers:
options.body instanceof FormData
? options.headers
: { "Content-Type": "application/json", ...options.headers },
});
if (!response.ok) {
const body = await response.json().catch(() => ({ detail: `请求失败 (${response.status})` }));
throw new Error(typeof body.detail === 'string' ? body.detail : `参数无效 (${response.status})`);
const body = await response
.json()
.catch(() => ({ detail: `请求失败 (${response.status})` }));
throw new Error(
typeof body.detail === "string"
? body.detail
: `参数无效 (${response.status})`,
);
}
return response.json();
}
export const post = <T,>(path: string, body: unknown = {}) => api<T>(path, { method: 'POST', body: JSON.stringify(body) });
export const post = <T>(path: string, body: unknown = {}) =>
api<T>(path, { method: "POST", body: JSON.stringify(body) });