From 305b3ed7315d7e8dac6ddccd8f2f4e9c60c32e98 Mon Sep 17 00:00:00 2001 From: Sakurasan <26715255+Sakurasan@users.noreply.github.com> Date: Thu, 27 Aug 2026 09:57:30 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=88=A0=E9=99=A4=E6=97=A0?= =?UTF-8?q?=E7=94=A8=E7=9A=84=E6=A8=A1=E5=9E=8B=E5=B1=95=E7=A4=BA=E5=90=8D?= =?UTF-8?q?=EF=BC=88display=5Fname=EF=BC=89=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 该字段仅存取、从不展示:管理列表只渲染 name,/v1/models 与用户侧 均不返回它。与渠道绑定 upstream_model 的名字映射职责重叠且悬空。 - store.Model 结构体、admin CRUD、seed 数据移除 display_name - 前端编辑弹窗输入框、表单状态、types.ts 同步移除 - 本地库已 ALTER TABLE DROP COLUMN;生产残留列无害 --- server/internal/api/admin_channel_models.go | 2 +- server/internal/api/admin_models.go | 14 +++----------- server/internal/app/app.go | 7 +++---- server/internal/store/models.go | 1 - web/src/types.ts | 1 - web/src/views/admin/ModelsView.vue | 7 ++----- 6 files changed, 9 insertions(+), 23 deletions(-) diff --git a/server/internal/api/admin_channel_models.go b/server/internal/api/admin_channel_models.go index babf801..cd9e938 100644 --- a/server/internal/api/admin_channel_models.go +++ b/server/internal/api/admin_channel_models.go @@ -118,7 +118,7 @@ func (h *Handler) AdminChannelAddModel(c *gin.Context) { // 解析或创建全局模型(客户端名) var m store.Model if err := h.a.DB.Where("name = ?", globalName).First(&m).Error; err != nil { - m = store.Model{Name: globalName, DisplayName: globalName, Enabled: true} + m = store.Model{Name: globalName, Enabled: true} if err := h.a.DB.Create(&m).Error; err != nil { resp.Fail(c, http.StatusInternalServerError, "failed to create model") return diff --git a/server/internal/api/admin_models.go b/server/internal/api/admin_models.go index 47bcd32..755d469 100644 --- a/server/internal/api/admin_models.go +++ b/server/internal/api/admin_models.go @@ -41,7 +41,7 @@ func (h *Handler) AdminModels(c *gin.Context) { needsPricing := used && m.InputPrice == 0 && m.OutputPrice == 0 && m.CacheReadPrice == 0 denied := containsStr(deny, m.Name) || (len(allow) > 0 && !containsStr(allow, m.Name)) out = append(out, gin.H{ - "id": m.ID, "name": m.Name, "display_name": m.DisplayName, + "id": m.ID, "name": m.Name, "input_price": m.InputPrice, "output_price": m.OutputPrice, "cache_read_price": m.CacheReadPrice, "enabled": m.Enabled, "sort": m.Sort, "channels": chs, "used": used, "needs_pricing": needsPricing, "denied": denied, @@ -119,7 +119,6 @@ func containsStr(list []string, s string) bool { func (h *Handler) AdminCreateModel(c *gin.Context) { var req struct { Name string `json:"name" binding:"required,min=1,max=128"` - DisplayName string `json:"display_name"` InputPrice float64 `json:"input_price"` OutputPrice float64 `json:"output_price"` CacheReadPrice float64 `json:"cache_read_price"` @@ -130,13 +129,10 @@ func (h *Handler) AdminCreateModel(c *gin.Context) { return } m := store.Model{ - Name: req.Name, DisplayName: req.DisplayName, + Name: req.Name, InputPrice: req.InputPrice, OutputPrice: req.OutputPrice, CacheReadPrice: req.CacheReadPrice, Enabled: boolOr(req.Enabled, true), } - if m.DisplayName == "" { - m.DisplayName = m.Name - } if err := h.a.DB.Create(&m).Error; err != nil { resp.Fail(c, http.StatusConflict, "failed to create model (name may already exist)") return @@ -144,7 +140,7 @@ func (h *Handler) AdminCreateModel(c *gin.Context) { resp.Created(c, gin.H{"id": m.ID, "name": m.Name}) } -// AdminUpdateModel PUT /api/v1/admin/models/:id — 价格/展示名/启停/排序。 +// AdminUpdateModel PUT /api/v1/admin/models/:id — 价格/启停/排序。 func (h *Handler) AdminUpdateModel(c *gin.Context) { id, err := strconv.ParseUint(c.Param("id"), 10, 64) if err != nil { @@ -152,7 +148,6 @@ func (h *Handler) AdminUpdateModel(c *gin.Context) { return } var req struct { - DisplayName *string `json:"display_name"` InputPrice *float64 `json:"input_price"` OutputPrice *float64 `json:"output_price"` CacheReadPrice *float64 `json:"cache_read_price"` @@ -169,9 +164,6 @@ func (h *Handler) AdminUpdateModel(c *gin.Context) { return } updates := map[string]any{} - if req.DisplayName != nil { - updates["display_name"] = *req.DisplayName - } if req.InputPrice != nil { updates["input_price"] = *req.InputPrice } diff --git a/server/internal/app/app.go b/server/internal/app/app.go index 556e13c..8d9b9f0 100644 --- a/server/internal/app/app.go +++ b/server/internal/app/app.go @@ -124,11 +124,10 @@ func (a *App) Seed() error { } // 默认模型 + 绑定 m := store.Model{ - Name: a.Cfg.Proxy.DefaultModel, - DisplayName: a.Cfg.Proxy.DefaultModel, - InputPrice: 0.15, // 每百万 token,示例价 + Name: a.Cfg.Proxy.DefaultModel, + InputPrice: 0.15, // 每百万 token,示例价 OutputPrice: 0.60, - Enabled: true, + Enabled: true, } if err := a.DB.Create(&m).Error; err == nil { a.DB.Create(&store.ChannelModelBinding{ChannelID: ch.ID, ModelID: m.ID, UpstreamModel: m.Name}) diff --git a/server/internal/store/models.go b/server/internal/store/models.go index 9921d3e..6c61e19 100644 --- a/server/internal/store/models.go +++ b/server/internal/store/models.go @@ -145,7 +145,6 @@ func (c *Channel) UpstreamURL(proto, path string) string { type Model struct { ID uint64 `gorm:"primaryKey;autoIncrement" json:"id"` Name string `gorm:"uniqueIndex;size:128;not null" json:"name"` - DisplayName string `gorm:"size:128" json:"display_name"` InputPrice float64 `gorm:"type:numeric(20,8);not null;default:0" json:"input_price"` OutputPrice float64 `gorm:"type:numeric(20,8);not null;default:0" json:"output_price"` CacheReadPrice float64 `gorm:"type:numeric(20,8);not null;default:0" json:"cache_read_price"` diff --git a/web/src/types.ts b/web/src/types.ts index 0f4a1ab..4ac7e82 100644 --- a/web/src/types.ts +++ b/web/src/types.ts @@ -59,7 +59,6 @@ export interface ModelBinding { export interface Model { id: number name: string - display_name: string input_price: number output_price: number cache_read_price: number diff --git a/web/src/views/admin/ModelsView.vue b/web/src/views/admin/ModelsView.vue index 4d19080..2e77da0 100644 --- a/web/src/views/admin/ModelsView.vue +++ b/web/src/views/admin/ModelsView.vue @@ -46,7 +46,6 @@ function quickAdd() { const form = reactive({ name: '', - display_name: '', input_price: 0, output_price: 0, cache_read_price: 0, @@ -65,14 +64,14 @@ async function load() { function openCreate() { editing.value = null - Object.assign(form, { name: '', display_name: '', input_price: 0, output_price: 0, cache_read_price: 0, enabled: true }) + Object.assign(form, { name: '', input_price: 0, output_price: 0, cache_read_price: 0, enabled: true }) editOpen.value = true } function openEdit(m: Model) { editing.value = m Object.assign(form, { - name: m.name, display_name: m.display_name, + name: m.name, input_price: m.input_price, output_price: m.output_price, cache_read_price: m.cache_read_price, enabled: m.enabled, }) @@ -82,7 +81,6 @@ function openEdit(m: Model) { async function save() { saving.value = true const payload = { - display_name: form.display_name || form.name, input_price: Number(form.input_price), output_price: Number(form.output_price), cache_read_price: Number(form.cache_read_price), @@ -207,7 +205,6 @@ onMounted(load)
-