refactor: 删除无用的模型展示名(display_name)字段

该字段仅存取、从不展示:管理列表只渲染 name,/v1/models 与用户侧
均不返回它。与渠道绑定 upstream_model 的名字映射职责重叠且悬空。
- store.Model 结构体、admin CRUD、seed 数据移除 display_name
- 前端编辑弹窗输入框、表单状态、types.ts 同步移除
- 本地库已 ALTER TABLE DROP COLUMN;生产残留列无害
This commit is contained in:
Sakurasan
2026-08-27 09:57:30 +08:00
parent 79545aa48e
commit 305b3ed731
6 changed files with 9 additions and 23 deletions
+1 -1
View File
@@ -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
+3 -11
View File
@@ -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
}