feat(settings): 扩展 SettingsData 加 compact 字段,后端解析与校验
This commit is contained in:
@@ -19,16 +19,17 @@ export function getSettings(raw: Database): SettingsData {
|
||||
.get();
|
||||
|
||||
if (!row) {
|
||||
return { theme: "system" };
|
||||
return { compact: false, theme: "system" };
|
||||
}
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(row.data) as Partial<SettingsData>;
|
||||
return {
|
||||
compact: typeof parsed.compact === "boolean" ? parsed.compact : false,
|
||||
theme: parsed.theme === "dark" || parsed.theme === "light" || parsed.theme === "system" ? parsed.theme : "system",
|
||||
};
|
||||
} catch {
|
||||
return { theme: "system" };
|
||||
return { compact: false, theme: "system" };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +41,7 @@ export function updateSettings(raw: Database, data: Partial<SettingsData>, _logg
|
||||
.where(and(eq(settings.id, SETTINGS_ID), notDeleted(settings)))
|
||||
.get();
|
||||
|
||||
let currentData: SettingsData = { theme: "system" };
|
||||
let currentData: SettingsData = { compact: false, theme: "system" };
|
||||
if (existing) {
|
||||
try {
|
||||
currentData = JSON.parse(existing.data) as SettingsData;
|
||||
|
||||
@@ -32,6 +32,10 @@ export async function handleUpdateSettings(
|
||||
return jsonResponse(createApiError("theme 仅支持 dark、light、system", 400), { mode, status: 400 });
|
||||
}
|
||||
|
||||
if (body.compact !== undefined && typeof body.compact !== "boolean") {
|
||||
return jsonResponse(createApiError("compact 必须为布尔值", 400), { mode, status: 400 });
|
||||
}
|
||||
|
||||
const result = updateSettings(db, body, logger);
|
||||
logger.info({ data: result }, "设置已更新");
|
||||
return jsonResponse(result, { mode });
|
||||
|
||||
@@ -238,6 +238,7 @@ export type ProviderType = "anthropic" | "openai" | "openai-compatible";
|
||||
export type RuntimeMode = "development" | "production" | "test";
|
||||
|
||||
export interface SettingsData {
|
||||
compact?: boolean;
|
||||
theme: ThemePreference;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user