Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
675e6138
Commit
675e6138
authored
Jan 12, 2026
by
cyhhao
Browse files
Merge branch 'main' of github.com:Wei-Shaw/sub2api
parents
67acac10
3b71bc3d
Changes
6
Hide whitespace changes
Inline
Side-by-side
backend/internal/handler/auth_handler.go
View file @
675e6138
...
@@ -3,6 +3,7 @@ package handler
...
@@ -3,6 +3,7 @@ package handler
import
(
import
(
"github.com/Wei-Shaw/sub2api/internal/config"
"github.com/Wei-Shaw/sub2api/internal/config"
"github.com/Wei-Shaw/sub2api/internal/handler/dto"
"github.com/Wei-Shaw/sub2api/internal/handler/dto"
"github.com/Wei-Shaw/sub2api/internal/pkg/ip"
"github.com/Wei-Shaw/sub2api/internal/pkg/response"
"github.com/Wei-Shaw/sub2api/internal/pkg/response"
middleware2
"github.com/Wei-Shaw/sub2api/internal/server/middleware"
middleware2
"github.com/Wei-Shaw/sub2api/internal/server/middleware"
"github.com/Wei-Shaw/sub2api/internal/service"
"github.com/Wei-Shaw/sub2api/internal/service"
...
@@ -76,7 +77,7 @@ func (h *AuthHandler) Register(c *gin.Context) {
...
@@ -76,7 +77,7 @@ func (h *AuthHandler) Register(c *gin.Context) {
// Turnstile 验证(当提供了邮箱验证码时跳过,因为发送验证码时已验证过)
// Turnstile 验证(当提供了邮箱验证码时跳过,因为发送验证码时已验证过)
if
req
.
VerifyCode
==
""
{
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
.
Get
ClientIP
(
c
));
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
response
.
ErrorFrom
(
c
,
err
)
return
return
}
}
...
@@ -105,7 +106,7 @@ func (h *AuthHandler) SendVerifyCode(c *gin.Context) {
...
@@ -105,7 +106,7 @@ func (h *AuthHandler) SendVerifyCode(c *gin.Context) {
}
}
// Turnstile 验证
// 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
.
Get
ClientIP
(
c
));
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
response
.
ErrorFrom
(
c
,
err
)
return
return
}
}
...
@@ -132,7 +133,7 @@ func (h *AuthHandler) Login(c *gin.Context) {
...
@@ -132,7 +133,7 @@ func (h *AuthHandler) Login(c *gin.Context) {
}
}
// Turnstile 验证
// 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
.
Get
ClientIP
(
c
));
err
!=
nil
{
response
.
ErrorFrom
(
c
,
err
)
response
.
ErrorFrom
(
c
,
err
)
return
return
}
}
...
...
backend/internal/handler/gemini_v1beta_handler.go
View file @
675e6138
...
@@ -12,6 +12,7 @@ import (
...
@@ -12,6 +12,7 @@ import (
"github.com/Wei-Shaw/sub2api/internal/pkg/antigravity"
"github.com/Wei-Shaw/sub2api/internal/pkg/antigravity"
"github.com/Wei-Shaw/sub2api/internal/pkg/gemini"
"github.com/Wei-Shaw/sub2api/internal/pkg/gemini"
"github.com/Wei-Shaw/sub2api/internal/pkg/googleapi"
"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/server/middleware"
"github.com/Wei-Shaw/sub2api/internal/service"
"github.com/Wei-Shaw/sub2api/internal/service"
...
@@ -316,7 +317,7 @@ func (h *GatewayHandler) GeminiV1BetaModels(c *gin.Context) {
...
@@ -316,7 +317,7 @@ func (h *GatewayHandler) GeminiV1BetaModels(c *gin.Context) {
// 捕获请求信息(用于异步记录,避免在 goroutine 中访问 gin.Context)
// 捕获请求信息(用于异步记录,避免在 goroutine 中访问 gin.Context)
userAgent
:=
c
.
GetHeader
(
"User-Agent"
)
userAgent
:=
c
.
GetHeader
(
"User-Agent"
)
clientIP
:=
c
.
ClientIP
()
clientIP
:=
ip
.
Get
ClientIP
(
c
)
// 6) record usage async
// 6) record usage async
go
func
(
result
*
service
.
ForwardResult
,
usedAccount
*
service
.
Account
,
ua
,
ip
string
)
{
go
func
(
result
*
service
.
ForwardResult
,
usedAccount
*
service
.
Account
,
ua
,
ip
string
)
{
...
...
backend/internal/handler/openai_gateway_handler.go
View file @
675e6138
...
@@ -12,6 +12,7 @@ import (
...
@@ -12,6 +12,7 @@ import (
"time"
"time"
"github.com/Wei-Shaw/sub2api/internal/config"
"github.com/Wei-Shaw/sub2api/internal/config"
"github.com/Wei-Shaw/sub2api/internal/pkg/ip"
"github.com/Wei-Shaw/sub2api/internal/pkg/openai"
"github.com/Wei-Shaw/sub2api/internal/pkg/openai"
middleware2
"github.com/Wei-Shaw/sub2api/internal/server/middleware"
middleware2
"github.com/Wei-Shaw/sub2api/internal/server/middleware"
"github.com/Wei-Shaw/sub2api/internal/service"
"github.com/Wei-Shaw/sub2api/internal/service"
...
@@ -265,7 +266,7 @@ func (h *OpenAIGatewayHandler) Responses(c *gin.Context) {
...
@@ -265,7 +266,7 @@ func (h *OpenAIGatewayHandler) Responses(c *gin.Context) {
// 捕获请求信息(用于异步记录,避免在 goroutine 中访问 gin.Context)
// 捕获请求信息(用于异步记录,避免在 goroutine 中访问 gin.Context)
userAgent
:=
c
.
GetHeader
(
"User-Agent"
)
userAgent
:=
c
.
GetHeader
(
"User-Agent"
)
clientIP
:=
c
.
ClientIP
()
clientIP
:=
ip
.
Get
ClientIP
(
c
)
// Async record usage
// Async record usage
go
func
(
result
*
service
.
OpenAIForwardResult
,
usedAccount
*
service
.
Account
,
ua
,
ip
string
)
{
go
func
(
result
*
service
.
OpenAIForwardResult
,
usedAccount
*
service
.
Account
,
ua
,
ip
string
)
{
...
...
backend/internal/handler/ops_error_logger.go
View file @
675e6138
...
@@ -15,6 +15,7 @@ import (
...
@@ -15,6 +15,7 @@ import (
"unicode/utf8"
"unicode/utf8"
"github.com/Wei-Shaw/sub2api/internal/pkg/ctxkey"
"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"
middleware2
"github.com/Wei-Shaw/sub2api/internal/server/middleware"
"github.com/Wei-Shaw/sub2api/internal/service"
"github.com/Wei-Shaw/sub2api/internal/service"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
...
@@ -522,7 +523,7 @@ func OpsErrorLoggerMiddleware(ops *service.OpsService) gin.HandlerFunc {
...
@@ -522,7 +523,7 @@ func OpsErrorLoggerMiddleware(ops *service.OpsService) gin.HandlerFunc {
}
}
var
clientIP
string
var
clientIP
string
if
ip
:=
strings
.
TrimSpace
(
c
.
ClientIP
());
ip
!=
""
{
if
ip
:=
strings
.
TrimSpace
(
ip
.
Get
ClientIP
(
c
));
ip
!=
""
{
clientIP
=
ip
clientIP
=
ip
entry
.
ClientIP
=
&
clientIP
entry
.
ClientIP
=
&
clientIP
}
}
...
@@ -682,7 +683,7 @@ func OpsErrorLoggerMiddleware(ops *service.OpsService) gin.HandlerFunc {
...
@@ -682,7 +683,7 @@ func OpsErrorLoggerMiddleware(ops *service.OpsService) gin.HandlerFunc {
}
}
var
clientIP
string
var
clientIP
string
if
ip
:=
strings
.
TrimSpace
(
c
.
ClientIP
());
ip
!=
""
{
if
ip
:=
strings
.
TrimSpace
(
ip
.
Get
ClientIP
(
c
));
ip
!=
""
{
clientIP
=
ip
clientIP
=
ip
entry
.
ClientIP
=
&
clientIP
entry
.
ClientIP
=
&
clientIP
}
}
...
...
frontend/src/i18n/locales/en.ts
View file @
675e6138
...
@@ -390,7 +390,7 @@ export default {
...
@@ -390,7 +390,7 @@ export default {
opencode
:
{
opencode
:
{
title
:
'
OpenCode Example
'
,
title
:
'
OpenCode Example
'
,
subtitle
:
'
opencode.json
'
,
subtitle
:
'
opencode.json
'
,
hint
:
'
This is a group configuratio
n example
. A
djust model and options as needed.
'
,
hint
:
'
Config path: ~/.config/opencode/opencode.json (create if not exists). This is a
n example
, a
djust model and options as needed.
'
,
},
},
},
},
customKeyLabel
:
'
Custom Key
'
,
customKeyLabel
:
'
Custom Key
'
,
...
...
frontend/src/i18n/locales/zh.ts
View file @
675e6138
...
@@ -387,7 +387,7 @@ export default {
...
@@ -387,7 +387,7 @@ export default {
opencode
:
{
opencode
:
{
title
:
'
OpenCode 配置示例
'
,
title
:
'
OpenCode 配置示例
'
,
subtitle
:
'
opencode.json
'
,
subtitle
:
'
opencode.json
'
,
hint
:
'
示例仅用于演示分组配置
,模型与选项可按需调整。
'
,
hint
:
'
配置文件路径:~/.config/opencode/opencode.json,不存在需手动创建。示例仅供参考
,模型与选项可按需调整。
'
,
},
},
},
},
customKeyLabel
:
'
自定义密钥
'
,
customKeyLabel
:
'
自定义密钥
'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment