From eb57a09c5d445d184626854e0c85605aa2e6b0d0 Mon Sep 17 00:00:00 2001 From: Sakurasan <26715255+Sakurasan@users.noreply.github.com> Date: Sat, 15 Aug 2026 20:55:26 +0800 Subject: [PATCH] =?UTF-8?q?API=20=E5=AF=86=E9=92=A5:=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E4=B8=8E=E9=AB=98=E7=BA=A7=E9=80=89=E9=A1=B9?= =?UTF-8?q?,=20=E4=BF=AE=E5=A4=8D=20jsonb=20=E7=99=BD=E5=90=8D=E5=8D=95?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 前端密钥页新增"编辑": 改名/每日配额/模型白名单/状态切换 - 新建密钥展开"高级选项": 每日 Token/请求上限、模型白名单 - 修复 PATCH 更新 allowed_models(jsonb)不走序列化导致失败, 改为 JSON 字符串写入, 跨 SQLite/Postgres 可靠 Co-Authored-By: Claude --- server/internal/api/keys.go | 12 ++- web/src/views/console/KeysView.vue | 131 ++++++++++++++++++++++++++--- 2 files changed, 130 insertions(+), 13 deletions(-) diff --git a/server/internal/api/keys.go b/server/internal/api/keys.go index 493a8f0..eb3b259 100644 --- a/server/internal/api/keys.go +++ b/server/internal/api/keys.go @@ -1,6 +1,7 @@ package api import ( + "encoding/json" "net/http" "strconv" "time" @@ -135,9 +136,6 @@ func (h *Handler) PatchKey(c *gin.Context) { if req.QuotaRequestsPerDay != nil { updates["quota_requests_per_day"] = *req.QuotaRequestsPerDay } - if req.AllowedModels != nil { - updates["allowed_models"] = *req.AllowedModels - } if req.Status != nil { if *req.Status != store.KeyStatusActive && *req.Status != store.KeyStatusRevoked { resp.Fail(c, http.StatusBadRequest, "status must be active or revoked") @@ -151,6 +149,14 @@ func (h *Handler) PatchKey(c *gin.Context) { return } } + // allowed_models 是 jsonb:手动序列化为 JSON 字符串写入(跨 SQLite/Postgres) + if req.AllowedModels != nil { + raw, _ := json.Marshal(*req.AllowedModels) + if err := h.a.DB.Model(&k).Update("allowed_models", string(raw)).Error; err != nil { + resp.Fail(c, http.StatusInternalServerError, "failed to update key") + return + } + } resp.OK(c, gin.H{"ok": true}) } diff --git a/web/src/views/console/KeysView.vue b/web/src/views/console/KeysView.vue index 6cdf839..b7c32f1 100644 --- a/web/src/views/console/KeysView.vue +++ b/web/src/views/console/KeysView.vue @@ -1,5 +1,5 @@