refactor(auth): replace direct token group setting with context key retrieval
This commit is contained in:
@@ -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)
|
common.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) {
|
||||||
|
|||||||
@@ -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 {
|
|||||||
//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 {
|
|||||||
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),
|
||||||
|
|||||||
Reference in New Issue
Block a user