fix: satisfy golangci-lint (nil checks, remove unused helpers)
This commit is contained in:
@@ -215,7 +215,6 @@ var (
|
|||||||
modelFieldRe = regexp.MustCompile(`"model"\s*:\s*"([^"]+)"`)
|
modelFieldRe = regexp.MustCompile(`"model"\s*:\s*"([^"]+)"`)
|
||||||
toolDescAbsPathRe = regexp.MustCompile(`/\/?(?:home|Users|tmp|var|opt|usr|etc)\/[^\s,\)"'\]]+`)
|
toolDescAbsPathRe = regexp.MustCompile(`/\/?(?:home|Users|tmp|var|opt|usr|etc)\/[^\s,\)"'\]]+`)
|
||||||
toolDescWinPathRe = regexp.MustCompile(`(?i)[A-Z]:\\[^\s,\)"'\]]+`)
|
toolDescWinPathRe = regexp.MustCompile(`(?i)[A-Z]:\\[^\s,\)"'\]]+`)
|
||||||
opencodeTextRe = regexp.MustCompile(`(?i)opencode`)
|
|
||||||
|
|
||||||
claudeToolNameOverrides = map[string]string{
|
claudeToolNameOverrides = map[string]string{
|
||||||
"bash": "Bash",
|
"bash": "Bash",
|
||||||
@@ -3320,11 +3319,16 @@ func (s *GatewayService) buildUpstreamRequest(ctx context.Context, c *gin.Contex
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clientHeaders := http.Header{}
|
||||||
|
if c != nil && c.Request != nil {
|
||||||
|
clientHeaders = c.Request.Header
|
||||||
|
}
|
||||||
|
|
||||||
// OAuth账号:应用统一指纹
|
// OAuth账号:应用统一指纹
|
||||||
var fingerprint *Fingerprint
|
var fingerprint *Fingerprint
|
||||||
if account.IsOAuth() && s.identityService != nil {
|
if account.IsOAuth() && s.identityService != nil {
|
||||||
// 1. 获取或创建指纹(包含随机生成的ClientID)
|
// 1. 获取或创建指纹(包含随机生成的ClientID)
|
||||||
fp, err := s.identityService.GetOrCreateFingerprint(ctx, account.ID, c.Request.Header)
|
fp, err := s.identityService.GetOrCreateFingerprint(ctx, account.ID, clientHeaders)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Warning: failed to get fingerprint for account %d: %v", account.ID, err)
|
log.Printf("Warning: failed to get fingerprint for account %d: %v", account.ID, err)
|
||||||
// 失败时降级为透传原始headers
|
// 失败时降级为透传原始headers
|
||||||
@@ -3355,7 +3359,7 @@ func (s *GatewayService) buildUpstreamRequest(ctx context.Context, c *gin.Contex
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 白名单透传headers
|
// 白名单透传headers
|
||||||
for key, values := range c.Request.Header {
|
for key, values := range clientHeaders {
|
||||||
lowerKey := strings.ToLower(key)
|
lowerKey := strings.ToLower(key)
|
||||||
if allowedHeaders[lowerKey] {
|
if allowedHeaders[lowerKey] {
|
||||||
for _, v := range values {
|
for _, v := range values {
|
||||||
@@ -3479,20 +3483,6 @@ func requestNeedsBetaFeatures(body []byte) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func requestHasTools(body []byte) bool {
|
|
||||||
tools := gjson.GetBytes(body, "tools")
|
|
||||||
if !tools.Exists() {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if tools.IsArray() {
|
|
||||||
return len(tools.Array()) > 0
|
|
||||||
}
|
|
||||||
if tools.IsObject() {
|
|
||||||
return len(tools.Map()) > 0
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func defaultAPIKeyBetaHeader(body []byte) string {
|
func defaultAPIKeyBetaHeader(body []byte) string {
|
||||||
modelID := gjson.GetBytes(body, "model").String()
|
modelID := gjson.GetBytes(body, "model").String()
|
||||||
if strings.Contains(strings.ToLower(modelID), "haiku") {
|
if strings.Contains(strings.ToLower(modelID), "haiku") {
|
||||||
@@ -4804,10 +4794,15 @@ func (s *GatewayService) buildCountTokensRequest(ctx context.Context, c *gin.Con
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clientHeaders := http.Header{}
|
||||||
|
if c != nil && c.Request != nil {
|
||||||
|
clientHeaders = c.Request.Header
|
||||||
|
}
|
||||||
|
|
||||||
// OAuth 账号:应用统一指纹和重写 userID
|
// OAuth 账号:应用统一指纹和重写 userID
|
||||||
// 如果启用了会话ID伪装,会在重写后替换 session 部分为固定值
|
// 如果启用了会话ID伪装,会在重写后替换 session 部分为固定值
|
||||||
if account.IsOAuth() && s.identityService != nil {
|
if account.IsOAuth() && s.identityService != nil {
|
||||||
fp, err := s.identityService.GetOrCreateFingerprint(ctx, account.ID, c.Request.Header)
|
fp, err := s.identityService.GetOrCreateFingerprint(ctx, account.ID, clientHeaders)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
accountUUID := account.GetExtraString("account_uuid")
|
accountUUID := account.GetExtraString("account_uuid")
|
||||||
if accountUUID != "" && fp.ClientID != "" {
|
if accountUUID != "" && fp.ClientID != "" {
|
||||||
@@ -4831,7 +4826,7 @@ func (s *GatewayService) buildCountTokensRequest(ctx context.Context, c *gin.Con
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 白名单透传 headers
|
// 白名单透传 headers
|
||||||
for key, values := range c.Request.Header {
|
for key, values := range clientHeaders {
|
||||||
lowerKey := strings.ToLower(key)
|
lowerKey := strings.ToLower(key)
|
||||||
if allowedHeaders[lowerKey] {
|
if allowedHeaders[lowerKey] {
|
||||||
for _, v := range values {
|
for _, v := range values {
|
||||||
@@ -4842,7 +4837,7 @@ func (s *GatewayService) buildCountTokensRequest(ctx context.Context, c *gin.Con
|
|||||||
|
|
||||||
// OAuth 账号:应用指纹到请求头
|
// OAuth 账号:应用指纹到请求头
|
||||||
if account.IsOAuth() && s.identityService != nil {
|
if account.IsOAuth() && s.identityService != nil {
|
||||||
fp, _ := s.identityService.GetOrCreateFingerprint(ctx, account.ID, c.Request.Header)
|
fp, _ := s.identityService.GetOrCreateFingerprint(ctx, account.ID, clientHeaders)
|
||||||
if fp != nil {
|
if fp != nil {
|
||||||
s.identityService.ApplyFingerprint(req, fp)
|
s.identityService.ApplyFingerprint(req, fp)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user