From 22ef9534e01a5542aaedb8321563c32dd5ff184e Mon Sep 17 00:00:00 2001 From: shaw Date: Mon, 12 Jan 2026 20:44:38 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=8F=8D=E5=90=91?= =?UTF-8?q?=E4=BB=A3=E7=90=86=E4=B8=8B=E5=AE=A2=E6=88=B7=E7=AB=AF=20IP=20?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/internal/handler/auth_handler.go | 7 ++++--- backend/internal/handler/gemini_v1beta_handler.go | 3 ++- backend/internal/handler/openai_gateway_handler.go | 3 ++- backend/internal/handler/ops_error_logger.go | 5 +++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/backend/internal/handler/auth_handler.go b/backend/internal/handler/auth_handler.go index c5cce937..882e4cf2 100644 --- a/backend/internal/handler/auth_handler.go +++ b/backend/internal/handler/auth_handler.go @@ -3,6 +3,7 @@ package handler import ( "github.com/Wei-Shaw/sub2api/internal/config" "github.com/Wei-Shaw/sub2api/internal/handler/dto" + "github.com/Wei-Shaw/sub2api/internal/pkg/ip" "github.com/Wei-Shaw/sub2api/internal/pkg/response" middleware2 "github.com/Wei-Shaw/sub2api/internal/server/middleware" "github.com/Wei-Shaw/sub2api/internal/service" @@ -76,7 +77,7 @@ func (h *AuthHandler) Register(c *gin.Context) { // Turnstile 验证(当提供了邮箱验证码时跳过,因为发送验证码时已验证过) if req.VerifyCode == "" { - if err := h.authService.VerifyTurnstile(c.Request.Context(), req.TurnstileToken, c.ClientIP()); err != nil { + if err := h.authService.VerifyTurnstile(c.Request.Context(), req.TurnstileToken, ip.GetClientIP(c)); err != nil { response.ErrorFrom(c, err) return } @@ -105,7 +106,7 @@ func (h *AuthHandler) SendVerifyCode(c *gin.Context) { } // Turnstile 验证 - if err := h.authService.VerifyTurnstile(c.Request.Context(), req.TurnstileToken, c.ClientIP()); err != nil { + if err := h.authService.VerifyTurnstile(c.Request.Context(), req.TurnstileToken, ip.GetClientIP(c)); err != nil { response.ErrorFrom(c, err) return } @@ -132,7 +133,7 @@ func (h *AuthHandler) Login(c *gin.Context) { } // Turnstile 验证 - if err := h.authService.VerifyTurnstile(c.Request.Context(), req.TurnstileToken, c.ClientIP()); err != nil { + if err := h.authService.VerifyTurnstile(c.Request.Context(), req.TurnstileToken, ip.GetClientIP(c)); err != nil { response.ErrorFrom(c, err) return } diff --git a/backend/internal/handler/gemini_v1beta_handler.go b/backend/internal/handler/gemini_v1beta_handler.go index 5c246456..2dddb856 100644 --- a/backend/internal/handler/gemini_v1beta_handler.go +++ b/backend/internal/handler/gemini_v1beta_handler.go @@ -12,6 +12,7 @@ import ( "github.com/Wei-Shaw/sub2api/internal/pkg/antigravity" "github.com/Wei-Shaw/sub2api/internal/pkg/gemini" "github.com/Wei-Shaw/sub2api/internal/pkg/googleapi" + "github.com/Wei-Shaw/sub2api/internal/pkg/ip" "github.com/Wei-Shaw/sub2api/internal/server/middleware" "github.com/Wei-Shaw/sub2api/internal/service" @@ -316,7 +317,7 @@ func (h *GatewayHandler) GeminiV1BetaModels(c *gin.Context) { // 捕获请求信息(用于异步记录,避免在 goroutine 中访问 gin.Context) userAgent := c.GetHeader("User-Agent") - clientIP := c.ClientIP() + clientIP := ip.GetClientIP(c) // 6) record usage async go func(result *service.ForwardResult, usedAccount *service.Account, ua, ip string) { diff --git a/backend/internal/handler/openai_gateway_handler.go b/backend/internal/handler/openai_gateway_handler.go index 8f6ef05f..3011b97d 100644 --- a/backend/internal/handler/openai_gateway_handler.go +++ b/backend/internal/handler/openai_gateway_handler.go @@ -12,6 +12,7 @@ import ( "time" "github.com/Wei-Shaw/sub2api/internal/config" + "github.com/Wei-Shaw/sub2api/internal/pkg/ip" "github.com/Wei-Shaw/sub2api/internal/pkg/openai" middleware2 "github.com/Wei-Shaw/sub2api/internal/server/middleware" "github.com/Wei-Shaw/sub2api/internal/service" @@ -265,7 +266,7 @@ func (h *OpenAIGatewayHandler) Responses(c *gin.Context) { // 捕获请求信息(用于异步记录,避免在 goroutine 中访问 gin.Context) userAgent := c.GetHeader("User-Agent") - clientIP := c.ClientIP() + clientIP := ip.GetClientIP(c) // Async record usage go func(result *service.OpenAIForwardResult, usedAccount *service.Account, ua, ip string) { diff --git a/backend/internal/handler/ops_error_logger.go b/backend/internal/handler/ops_error_logger.go index f0c271bd..13bd9d94 100644 --- a/backend/internal/handler/ops_error_logger.go +++ b/backend/internal/handler/ops_error_logger.go @@ -15,6 +15,7 @@ import ( "unicode/utf8" "github.com/Wei-Shaw/sub2api/internal/pkg/ctxkey" + "github.com/Wei-Shaw/sub2api/internal/pkg/ip" middleware2 "github.com/Wei-Shaw/sub2api/internal/server/middleware" "github.com/Wei-Shaw/sub2api/internal/service" "github.com/gin-gonic/gin" @@ -522,7 +523,7 @@ func OpsErrorLoggerMiddleware(ops *service.OpsService) gin.HandlerFunc { } var clientIP string - if ip := strings.TrimSpace(c.ClientIP()); ip != "" { + if ip := strings.TrimSpace(ip.GetClientIP(c)); ip != "" { clientIP = ip entry.ClientIP = &clientIP } @@ -682,7 +683,7 @@ func OpsErrorLoggerMiddleware(ops *service.OpsService) gin.HandlerFunc { } var clientIP string - if ip := strings.TrimSpace(c.ClientIP()); ip != "" { + if ip := strings.TrimSpace(ip.GetClientIP(c)); ip != "" { clientIP = ip entry.ClientIP = &clientIP } From 3b71bc3df1569968572eec2af3e8eb28e4d9a6b1 Mon Sep 17 00:00:00 2001 From: shaw Date: Mon, 12 Jan 2026 20:49:54 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20OpenCode=20=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=8F=90=E7=A4=BA=E6=B7=BB=E5=8A=A0=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E8=B7=AF=E5=BE=84=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/i18n/locales/en.ts | 2 +- frontend/src/i18n/locales/zh.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/i18n/locales/en.ts b/frontend/src/i18n/locales/en.ts index 4443514b..7482e018 100644 --- a/frontend/src/i18n/locales/en.ts +++ b/frontend/src/i18n/locales/en.ts @@ -390,7 +390,7 @@ export default { opencode: { title: 'OpenCode Example', subtitle: 'opencode.json', - hint: 'This is a group configuration example. Adjust model and options as needed.', + hint: 'Config path: ~/.config/opencode/opencode.json (create if not exists). This is an example, adjust model and options as needed.', }, }, customKeyLabel: 'Custom Key', diff --git a/frontend/src/i18n/locales/zh.ts b/frontend/src/i18n/locales/zh.ts index 12c67629..56827a76 100644 --- a/frontend/src/i18n/locales/zh.ts +++ b/frontend/src/i18n/locales/zh.ts @@ -387,7 +387,7 @@ export default { opencode: { title: 'OpenCode 配置示例', subtitle: 'opencode.json', - hint: '示例仅用于演示分组配置,模型与选项可按需调整。', + hint: '配置文件路径:~/.config/opencode/opencode.json,不存在需手动创建。示例仅供参考,模型与选项可按需调整。', }, }, customKeyLabel: '自定义密钥',