feat: 全局设置系统 — settings 表、CRUD 路由、主题偏好持久化

This commit is contained in:
2026-06-05 23:10:32 +08:00
parent e2eba6dc1f
commit 3f88e33bd1
23 changed files with 652 additions and 54 deletions

View File

@@ -18,6 +18,12 @@ function createMockHandler(overrides?: { status?: "active" | "archived" }) {
const project = { ...MOCK_PROJECT, ...overrides };
const handler = (input: RequestInfo | URL) => {
const url = input instanceof Request ? input.url : typeof input === "string" ? input : input.toString();
if (url.includes("/api/settings")) {
return new Response(JSON.stringify({ theme: "system" }), {
headers: { "Content-Type": "application/json" },
status: 200,
});
}
if (url.includes("/api/meta")) {
return new Response(
JSON.stringify({ ok: true, service: "test-app", timestamp: new Date().toISOString(), version: "0.1.0" }),
@@ -38,7 +44,8 @@ function createMockHandler(overrides?: { status?: "active" | "archived" }) {
}
return new Response(JSON.stringify({ error: "Not Found" }), { status: 404 });
};
const mocked = handler as unknown as typeof fetch;
const mocked = ((input: RequestInfo | URL, _init?: RequestInit) =>
Promise.resolve(handler(input))) as unknown as typeof fetch;
globalThis.fetch = mocked;
window.fetch = mocked;
}