feat(admin): 新增管理后台模型渠道配置功能

- 实现了管理后台模型渠道的增删改查功能
- 将前端直接调用API改为通过后端接口代理获取模型列表
- 添加了渠道测试连接和模型可用性检测功能
- 实现了API Key安全存储机制,前端不再明文显示
- 更新了管理后台设置页面的渠道配置界面
- 添加了表格选中行背景色主题配置支持
- 重构了错误处理机制,统一返回安全错误信息
- 整理了后端模型代理路径为OpenAI风格的/api/v1/*
This commit is contained in:
HouYunFei
2026-05-22 15:29:31 +08:00
parent 499439d66b
commit db5d114428
10 changed files with 321 additions and 83 deletions
+4
View File
@@ -25,6 +25,10 @@ func Fail(w http.ResponseWriter, msg string) {
func FailError(w http.ResponseWriter, err error) {
log.Printf("request failed: %v", err)
if safe, ok := err.(interface{ SafeMessage() string }); ok {
Fail(w, safe.SafeMessage())
return
}
Fail(w, "操作失败")
}
+28
View File
@@ -8,6 +8,12 @@ import (
"github.com/basketikun/infinite-canvas/service"
)
type adminChannelActionRequest struct {
Index *int `json:"index"`
Channel model.ModelChannel `json:"channel"`
Model string `json:"model"`
}
func Settings(w http.ResponseWriter, r *http.Request) {
settings, err := service.PublicSettings()
if err != nil {
@@ -36,3 +42,25 @@ func AdminSaveSettings(w http.ResponseWriter, r *http.Request) {
}
OK(w, result)
}
func AdminChannelModels(w http.ResponseWriter, r *http.Request) {
var request adminChannelActionRequest
_ = json.NewDecoder(r.Body).Decode(&request)
models, err := service.AdminChannelModels(request.Index, request.Channel)
if err != nil {
FailError(w, err)
return
}
OK(w, models)
}
func AdminTestChannelModel(w http.ResponseWriter, r *http.Request) {
var request adminChannelActionRequest
_ = json.NewDecoder(r.Body).Decode(&request)
result, err := service.AdminTestChannelModel(request.Index, request.Channel, request.Model)
if err != nil {
FailError(w, err)
return
}
OK(w, result)
}