Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e0a79e85
authored
Dec 13, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(auth): replace direct token group setting with context key retrieval
parent
6e998eaf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
3 deletions
+9
-3
middleware/auth.go
+1
-1
relay/common/relay_info.go
+8
-2
No files found.
middleware/auth.go
View file @
e0a79e85
...
@@ -307,7 +307,7 @@ func SetupContextForToken(c *gin.Context, token *model.Token, parts ...string) e
...
@@ -307,7 +307,7 @@ func SetupContextForToken(c *gin.Context, token *model.Token, parts ...string) e
}
else
{
}
else
{
c
.
Set
(
"token_model_limit_enabled"
,
false
)
c
.
Set
(
"token_model_limit_enabled"
,
false
)
}
}
c
.
Set
(
"token_group"
,
token
.
Group
)
c
ommon
.
SetContextKey
(
c
,
constant
.
ContextKeyTokenGroup
,
token
.
Group
)
c
.
Set
(
"token_cross_group_retry"
,
token
.
CrossGroupRetry
)
c
.
Set
(
"token_cross_group_retry"
,
token
.
CrossGroupRetry
)
if
len
(
parts
)
>
1
{
if
len
(
parts
)
>
1
{
if
model
.
IsAdmin
(
token
.
UserId
)
{
if
model
.
IsAdmin
(
token
.
UserId
)
{
...
...
relay/common/relay_info.go
View file @
e0a79e85
...
@@ -83,7 +83,7 @@ type RelayInfo struct {
...
@@ -83,7 +83,7 @@ type RelayInfo struct {
TokenKey
string
TokenKey
string
TokenGroup
string
TokenGroup
string
UserId
int
UserId
int
UsingGroup
string
// 使用的分组
UsingGroup
string
// 使用的分组
,当auto跨分组重试时,会变动
UserGroup
string
// 用户所在分组
UserGroup
string
// 用户所在分组
TokenUnlimited
bool
TokenUnlimited
bool
StartTime
time
.
Time
StartTime
time
.
Time
...
@@ -374,6 +374,12 @@ func genBaseRelayInfo(c *gin.Context, request dto.Request) *RelayInfo {
...
@@ -374,6 +374,12 @@ func genBaseRelayInfo(c *gin.Context, request dto.Request) *RelayInfo {
//channelId := common.GetContextKeyInt(c, constant.ContextKeyChannelId)
//channelId := common.GetContextKeyInt(c, constant.ContextKeyChannelId)
//paramOverride := common.GetContextKeyStringMap(c, constant.ContextKeyChannelParamOverride)
//paramOverride := common.GetContextKeyStringMap(c, constant.ContextKeyChannelParamOverride)
tokenGroup
:=
common
.
GetContextKeyString
(
c
,
constant
.
ContextKeyTokenGroup
)
// 当令牌分组为空时,表示使用用户分组
if
tokenGroup
==
""
{
tokenGroup
=
common
.
GetContextKeyString
(
c
,
constant
.
ContextKeyUserGroup
)
}
startTime
:=
common
.
GetContextKeyTime
(
c
,
constant
.
ContextKeyRequestStartTime
)
startTime
:=
common
.
GetContextKeyTime
(
c
,
constant
.
ContextKeyRequestStartTime
)
if
startTime
.
IsZero
()
{
if
startTime
.
IsZero
()
{
startTime
=
time
.
Now
()
startTime
=
time
.
Now
()
...
@@ -401,7 +407,7 @@ func genBaseRelayInfo(c *gin.Context, request dto.Request) *RelayInfo {
...
@@ -401,7 +407,7 @@ func genBaseRelayInfo(c *gin.Context, request dto.Request) *RelayInfo {
TokenId
:
common
.
GetContextKeyInt
(
c
,
constant
.
ContextKeyTokenId
),
TokenId
:
common
.
GetContextKeyInt
(
c
,
constant
.
ContextKeyTokenId
),
TokenKey
:
common
.
GetContextKeyString
(
c
,
constant
.
ContextKeyTokenKey
),
TokenKey
:
common
.
GetContextKeyString
(
c
,
constant
.
ContextKeyTokenKey
),
TokenUnlimited
:
common
.
GetContextKeyBool
(
c
,
constant
.
ContextKeyTokenUnlimited
),
TokenUnlimited
:
common
.
GetContextKeyBool
(
c
,
constant
.
ContextKeyTokenUnlimited
),
TokenGroup
:
common
.
GetContextKeyString
(
c
,
constant
.
ContextKeyTokenGroup
)
,
TokenGroup
:
tokenGroup
,
isFirstResponse
:
true
,
isFirstResponse
:
true
,
RelayMode
:
relayconstant
.
Path2RelayMode
(
c
.
Request
.
URL
.
Path
),
RelayMode
:
relayconstant
.
Path2RelayMode
(
c
.
Request
.
URL
.
Path
),
...
...
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