From 0b20a17074e056590a84edee950b17f3c8bdadd9 Mon Sep 17 00:00:00 2001 From: npc0-hue Date: Tue, 31 Mar 2026 15:02:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A4=E8=BD=AC=E5=8F=91body?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/server/model/gaia/response/system.go | 18 +++++++++++------- admin/server/service/gaia/model_provider.go | 19 ++++++++----------- admin/server/service/system/sys_initdb.go | 2 +- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/admin/server/model/gaia/response/system.go b/admin/server/model/gaia/response/system.go index cccca1060..567043c9c 100644 --- a/admin/server/model/gaia/response/system.go +++ b/admin/server/model/gaia/response/system.go @@ -2,9 +2,14 @@ package response import "time" +type CheckAccountQuotaRow struct { + TotalQuota float64 `gorm:"column:total_quota"` + UsedQuota float64 `gorm:"column:used_quota"` +} + // ForwardTokenInfo 转发 Token 列表项(不暴露内部 ID) type ForwardTokenInfo struct { - ID string `json:"id"` // token + ID string `json:"id"` // token Seq int `json:"seq"` // 1..N 序列号(用于删除) CreatedAt time.Time `json:"created_at"` } @@ -18,10 +23,9 @@ type ForwardTokensResponse struct { // TestEmailApiConfigResponse 测试邮箱 API 配置响应 type TestEmailApiConfigResponse struct { - StatusCode int `json:"status_code"` // HTTP 状态码 - Body interface{} `json:"body"` // 响应 Body(JSON 时为对象,否则为字符串) - EmailFieldPreview string `json:"email_field_preview"` // 邮箱字段解析预览(如 data[0].userName = test@example.com) - IsValid bool `json:"is_valid"` // 配置是否有效(能正确提取邮箱) - ErrorMessage string `json:"error_message,omitempty"` // 错误信息(可选) + StatusCode int `json:"status_code"` // HTTP 状态码 + Body interface{} `json:"body"` // 响应 Body(JSON 时为对象,否则为字符串) + EmailFieldPreview string `json:"email_field_preview"` // 邮箱字段解析预览(如 data[0].userName = test@example.com) + IsValid bool `json:"is_valid"` // 配置是否有效(能正确提取邮箱) + ErrorMessage string `json:"error_message,omitempty"` // 错误信息(可选) } - diff --git a/admin/server/service/gaia/model_provider.go b/admin/server/service/gaia/model_provider.go index 864c10d6e..1bf390006 100644 --- a/admin/server/service/gaia/model_provider.go +++ b/admin/server/service/gaia/model_provider.go @@ -14,6 +14,13 @@ import ( "encoding/pem" "errors" "fmt" + "io" + "net/http" + "os" + "strings" + "sync" + "time" + "github.com/flipped-aurora/gin-vue-admin/server/global" "github.com/flipped-aurora/gin-vue-admin/server/model/gaia" gaiaRequest "github.com/flipped-aurora/gin-vue-admin/server/model/gaia/request" @@ -23,12 +30,6 @@ import ( "go.gnd.pw/crypto/eax" "go.uber.org/zap" "gorm.io/gorm" - "io" - "net/http" - "os" - "strings" - "sync" - "time" ) // fetchAdminToken 查询一个管理员用户,生成 Dify Console API 兼容的 JWT。 @@ -205,10 +206,7 @@ func calcQuotaDelta(pricing *gaia.ModelPricing, modelName string, promptTokens, // CheckAccountQuota 检查用户是否还有可用余额(total_quota - used_quota > 0)。 // total_quota = 0 视为"未设置限额",不拦截;total_quota > 0 时才做余额校验。 func (s *ModelProviderService) CheckAccountQuota(userID string) error { - var row struct { - TotalQuota float64 `gorm:"column:total_quota"` - UsedQuota float64 `gorm:"column:used_quota"` - } + var row gaiaResponse.CheckAccountQuotaRow err := global.GVA_DB.Table("account_money_extend"). Select("total_quota, used_quota"). Where("account_id = ?::uuid", userID). @@ -1209,7 +1207,6 @@ func (s *ModelProviderService) ProxyRequest( requestURL = base + "/" + path } - fmt.Println("path", requestURL, string(body)) httpReq, err := http.NewRequest(method, requestURL, bodyReader) if err != nil { return err diff --git a/admin/server/service/system/sys_initdb.go b/admin/server/service/system/sys_initdb.go index 510ca07c1..499d59792 100644 --- a/admin/server/service/system/sys_initdb.go +++ b/admin/server/service/system/sys_initdb.go @@ -97,7 +97,7 @@ func (initDBService *InitDBService) IfInit() (init bool) { var authority modelSystem.SysAuthority global.GVA_DB.Model(&menu).Count(&menuCount) global.GVA_DB.Model(&authority).Count(&authorityCount) - if menuCount == 0 && authorityCount == 1 { + if menuCount <= 1 && authorityCount <= 1 { init = false } }