feat: 接口统一优化

This commit is contained in:
2026-05-23 13:45:58 +08:00
parent a3b1fba3ea
commit 7d68db723b
20 changed files with 302 additions and 302 deletions
+16
View File
@@ -0,0 +1,16 @@
// server/utils/response.ts - 统一 API 响应工具函数(非 OCS 接口专用)
// OCS 搜题接口 /api/search 有固定的兼容格式,不使用此工具
/** 成功响应:code 0data 为业务数据,msg 固定为"请求成功" */
export const apiOk = <T>(data: T) => ({
code: 0 as const,
data,
msg: "请求成功"
});
/** 错误响应:data 固定为 null,msg 为本地安全文案,不暴露上游细节 */
export const apiErr = (code: number, msg: string) => ({
code,
data: null,
msg
});