Files
Mdeical_Sur_Report/docs/modules/system-settings.md
admin 8de3a12dc1 Remove legacy settings secret migration
- Remove the super-admin one-time migration from browser local settings into backend AI and speech settings.

- Delete the migration-specific SystemSettings unit test that no longer matches the desired behavior.

- Restore feature, module, testing, and progress docs so settings secrets are documented as backend-managed only.
2026-05-02 02:26:21 +08:00

2.8 KiB
Raw Blame History

模块文档:系统设置

涉及文件

  • src/pages/SystemSettings.tsx
  • src/api/settings.ts
  • src/types.ts
  • src/utils/storage.ts
  • server/src/settings

模块职责

系统设置负责维护视频抽帧、AI 接口、讯飞语音和默认模板配置。超级管理员可以看到全部设置;其他用户主要配置默认报告模板。

页面优先调用 GET /api/settings/system 读取设置,保存时调用 PATCH /api/settings/system。只有开发模式或显式开启 VITE_ENABLE_LOCAL_FALLBACK=trueAPI 不可用才保留 localStorage.systemSettings 回退。后端使用 SystemSetting 表保存全局设置,并用 scope = user:<id> 保存个人默认模板。

视频抽帧配置

配置字段包括:

  • frameCount:抽取帧数。
  • framePositions:每帧对应的视频进度百分比。
  • frameMode:调整帧数时使用整体均匀抽取或保持当前抽帧。
  • autoInsertFrames:是否自动插入关键帧。
  • autoInsertDelay:自动插入延迟。
  • autoInsertFrameIndices:哪些抽帧序号参与自动插入。

保存时会对 framePositions 排序,并把 frameCount 同步为位置数组长度。

AI 接口配置

activeAiProvider 指向当前服务商,aiProviders 保存各服务商配置。默认服务商包括:

  • Kimi
  • DeepSeek
  • OpenAI
  • Custom

系统通过后端 /api/ai/models 测试连接和获取模型列表,通过 /api/ai/chat 在报告编辑器中生成内容。后端读取全局共用 Provider Key 并代理 OpenAI 兼容 /models/chat/completions,普通用户读取设置时不会拿到 AI Key。

讯飞语音配置

xfSpeechConfig 保存讯飞 WebSocket IAT 所需的 APPID、APIKey 和 APISecret。报告编辑器只连接本系统 /api/speech/iat,由后端读取这些配置、生成讯飞鉴权 URL 并转发音频和识别结果。普通用户读取设置时不会拿到 APIKey/APISecret。

默认模板

defaultTemplate 指向模板 ID。新建报告时如果当前用户可见该模板编辑器会自动加载对应模板内容否则回退到默认内置报告内容。

重置能力

超级管理员可执行:

  • 恢复系统设置出厂设置:优先调用 POST /api/settings/system/reset,只有本地回退开启时失败才重置本地 systemSettings
  • 重置全部数据:仅本地回退开启时执行 localStorage.clear() 并刷新;生产构建默认阻止把本地清空误认为后端数据重置。

注意事项

  • systemSettings 的本地混淆不等于安全加密;当前仅作为开发/显式本地回退模式下 API 不可用时的兼容缓存。
  • 初始化、类型和系统设置页面已统一使用 xfSpeechConfig;当前由后端语音代理使用。
  • 默认 API Key 或语音密钥不应留在生产前端代码中。