fix: 模型列表仅显示已启用渠道中的模型
This commit is contained in:
@@ -49,15 +49,22 @@ func (h *Handler) todayUsage(c *gin.Context, userID uint64) gin.H {
|
||||
}
|
||||
|
||||
// UserModels GET /api/v1/user/models — 控制台可用模型列表(无需 API Key)。
|
||||
// 仅返回启用的模型且至少绑定到一个启用且健康的渠道,与 /v1/models 口径一致。
|
||||
func (h *Handler) UserModels(c *gin.Context) {
|
||||
var ms []store.Model
|
||||
if err := h.a.DB.Where("enabled = ?", true).Order("sort ASC, id ASC").Find(&ms).Error; err != nil {
|
||||
var names []string
|
||||
if err := h.a.DB.Table("models").
|
||||
Joins("JOIN channel_model_bindings ON channel_model_bindings.model_id = models.id").
|
||||
Joins("JOIN channels ON channels.id = channel_model_bindings.channel_id").
|
||||
Where("models.enabled = ? AND channels.enabled = ? AND channels.health_status = ?",
|
||||
true, true, store.ChannelHealthHealthy).
|
||||
Distinct("models.name").
|
||||
Order("models.sort ASC, models.id ASC").
|
||||
Pluck("models.name", &names).Error; err != nil {
|
||||
resp.Fail(c, http.StatusInternalServerError, "failed to load models")
|
||||
return
|
||||
}
|
||||
out := make([]string, 0, len(ms))
|
||||
for _, m := range ms {
|
||||
out = append(out, m.Name)
|
||||
if names == nil {
|
||||
names = []string{}
|
||||
}
|
||||
resp.OK(c, gin.H{"items": out})
|
||||
resp.OK(c, gin.H{"items": names})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user