feat: 添加注册开关功能,优化系统配置与注册接口
ocs-nuxt / deploy (push) Failing after 11s

This commit is contained in:
2026-05-23 23:48:30 +08:00
parent bc785ac1ce
commit 5e99e28e8b
15 changed files with 371 additions and 48 deletions
+14 -4
View File
@@ -17,6 +17,8 @@ export interface SysConfig {
temperature: number;
/** 单行 SSE data 最大字节数,防止异常流无限堆内存 */
maxSseLineBytes: number;
/** 是否允许新用户注册;false 时注册接口直接拒绝 */
allowRegistration: boolean;
}
// system_config 表 key 字段的常量映射
@@ -26,7 +28,8 @@ const CONFIG_KEYS = {
openAiModel: "openai_model",
maxTokens: "max_tokens",
temperature: "temperature",
maxSseLineBytes: "openai_stream_max_sse_line_bytes"
maxSseLineBytes: "openai_stream_max_sse_line_bytes",
allowRegistration: "allow_registration"
} as const;
// 硬编码默认值,与原 env.ts 的 fallback 保持一致
@@ -36,7 +39,9 @@ const DEFAULTS: SysConfig = {
openAiModel: "gpt-5.2",
maxTokens: 500,
temperature: 0.7,
maxSseLineBytes: 1_048_576
maxSseLineBytes: 1_048_576,
// 默认开放注册;管理员可通过系统配置关闭
allowRegistration: true
};
// 内存缓存:减少每请求查 DB 的开销
@@ -82,7 +87,10 @@ export const getSysConfig = async (): Promise<SysConfig> => {
openAiModel: str(CONFIG_KEYS.openAiModel, DEFAULTS.openAiModel),
maxTokens: int(CONFIG_KEYS.maxTokens, DEFAULTS.maxTokens),
temperature: float(CONFIG_KEYS.temperature, DEFAULTS.temperature),
maxSseLineBytes: int(CONFIG_KEYS.maxSseLineBytes, DEFAULTS.maxSseLineBytes)
maxSseLineBytes: int(CONFIG_KEYS.maxSseLineBytes, DEFAULTS.maxSseLineBytes),
// "true" 以外的值均视为关闭;空值(未设置)走默认值 true
allowRegistration:
(map.get(CONFIG_KEYS.allowRegistration) ?? "true") !== "false"
};
_cachedConfig = config;
@@ -144,7 +152,9 @@ export const getUserEffectiveApiConfig = async (
openAiModel: customModel.length > 0 ? customModel : sysCfg.openAiModel,
maxTokens: userConfig.customMaxTokens ?? sysCfg.maxTokens,
temperature: userConfig.customTemperature ?? sysCfg.temperature,
maxSseLineBytes: sysCfg.maxSseLineBytes
maxSseLineBytes: sysCfg.maxSseLineBytes,
// 用户有效配置不改变注册开关,手带系统值
allowRegistration: sysCfg.allowRegistration
};
};