官网开发中 0803

This commit is contained in:
eafonyang
2026-08-03 19:09:03 +08:00
parent eeccdb079c
commit f37b6451ef
36 changed files with 1906 additions and 78 deletions
+16
View File
@@ -0,0 +1,16 @@
/**
* 安全解析后端 JSON 字段
*
* dashboard 的 JSON 列(s2_features、s1_faq_categories、options_json 等)
* 经 Drizzle ORM 返回时可能是字符串或已解析对象,统一转为对象数组。
*/
export function parseJson<T>(value: string | T | null | undefined, fallback: T): T {
if (value == null) return fallback;
if (typeof value !== 'string') return value as T;
try {
const parsed = JSON.parse(value) as T;
return parsed;
} catch {
return fallback;
}
}