mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-18 09:36:37 +08:00
refactor: Refactor token handling in the controller
- Remove the unnecessary `AddRemainQuota` field from `updateTokenDto` struct - Adjust `cleanToken.RemainQuota` by subtracting `tokenPatch.AddUsedQuota` - Increase `cleanToken.UsedQuota` by adding `tokenPatch.AddUsedQuota` - Update `model.RecordLog` call to include `tokenPatch.AddReason` and `tokenPatch.AddUsedQuota` values
This commit is contained in:
parent
edacd13025
commit
a0dc7e6fd6
@ -168,8 +168,6 @@ type updateTokenDto struct {
|
|||||||
ExpiredTime *int64 `json:"expired_time" gorm:"bigint;default:-1"` // -1 means never expired
|
ExpiredTime *int64 `json:"expired_time" gorm:"bigint;default:-1"` // -1 means never expired
|
||||||
RemainQuota *int `json:"remain_quota" gorm:"default:0"`
|
RemainQuota *int `json:"remain_quota" gorm:"default:0"`
|
||||||
UnlimitedQuota *bool `json:"unlimited_quota" gorm:"default:false"`
|
UnlimitedQuota *bool `json:"unlimited_quota" gorm:"default:false"`
|
||||||
// AddRemainQuota add or subtract remain quota
|
|
||||||
AddRemainQuota int `json:"add_remain_quota" gorm:"-"`
|
|
||||||
// AddUsedQuota add or subtract used quota
|
// AddUsedQuota add or subtract used quota
|
||||||
AddUsedQuota int `json:"add_used_quota" gorm:"-"`
|
AddUsedQuota int `json:"add_used_quota" gorm:"-"`
|
||||||
AddReason string `json:"add_reason" gorm:"-"`
|
AddReason string `json:"add_reason" gorm:"-"`
|
||||||
@ -243,15 +241,12 @@ func UpdateToken(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanToken.RemainQuota += tokenPatch.AddRemainQuota
|
cleanToken.RemainQuota -= tokenPatch.AddUsedQuota
|
||||||
cleanToken.UsedQuota += tokenPatch.AddUsedQuota
|
cleanToken.UsedQuota += tokenPatch.AddUsedQuota
|
||||||
|
|
||||||
if tokenPatch.AddUsedQuota != 0 {
|
if tokenPatch.AddUsedQuota != 0 {
|
||||||
model.RecordLog(userId, model.LogTypeConsume, fmt.Sprintf("外部(%s)消耗 %s", tokenPatch.AddReason, common.LogQuota(tokenPatch.AddUsedQuota)))
|
model.RecordLog(userId, model.LogTypeConsume, fmt.Sprintf("外部(%s)消耗 %s", tokenPatch.AddReason, common.LogQuota(tokenPatch.AddUsedQuota)))
|
||||||
}
|
}
|
||||||
if tokenPatch.AddRemainQuota != 0 {
|
|
||||||
model.RecordLog(userId, model.LogTypeManage, fmt.Sprintf("修改令牌可用额度(%s) %s", tokenPatch.AddReason, common.LogQuota(tokenPatch.AddRemainQuota)))
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = cleanToken.Update(); err != nil {
|
if err = cleanToken.Update(); err != nil {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
Loading…
Reference in New Issue
Block a user