mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-19 18:16:38 +08:00
chore: decrease token quota in ConsumeToken function
This commit modifies the ConsumeToken function in the token.go file to decrease the token quota by the specified amount. It replaces the previous code that directly updated the quota values with a call to the DecreaseTokenQuota function from the model package. This change improves code clarity and maintainability. Closes #123
This commit is contained in:
parent
671039f050
commit
4fd0b247d2
@ -279,8 +279,14 @@ func ConsumeToken(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanToken.UsedQuota += int64(tokenPatch.AddUsedQuota)
|
if err = model.DecreaseTokenQuota(cleanToken.Id, int64(tokenPatch.AddUsedQuota)); err != nil {
|
||||||
cleanToken.RemainQuota -= int64(tokenPatch.AddUsedQuota)
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"success": false,
|
||||||
|
"message": err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
model.RecordConsumeLog(c.Request.Context(),
|
model.RecordConsumeLog(c.Request.Context(),
|
||||||
userID, 0, 0, 0, tokenPatch.AddReason, cleanToken.Name,
|
userID, 0, 0, 0, tokenPatch.AddReason, cleanToken.Name,
|
||||||
int64(tokenPatch.AddUsedQuota),
|
int64(tokenPatch.AddUsedQuota),
|
||||||
|
Loading…
Reference in New Issue
Block a user