mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-21 19:16:36 +08:00
feat:Exclude fields from database schema and add additional field to struct
- Add `gorm:"-"` tag to exclude certain fields from the database schema - Add `AddReason` field to the `updateTokenDto` struct - Record consumption log if `AddUsedQuota` is non-zero - Record token quota modification log if `AddRemainQuota` is non-zero - Update and save `cleanToken` with new values
This commit is contained in:
parent
f979181b5f
commit
edacd13025
@ -169,9 +169,10 @@ type updateTokenDto struct {
|
|||||||
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 add or subtract remain quota
|
||||||
AddRemainQuota int `json:"add_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"`
|
AddUsedQuota int `json:"add_used_quota" gorm:"-"`
|
||||||
|
AddReason string `json:"add_reason" gorm:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateToken(c *gin.Context) {
|
func UpdateToken(c *gin.Context) {
|
||||||
@ -245,6 +246,13 @@ func UpdateToken(c *gin.Context) {
|
|||||||
cleanToken.RemainQuota += tokenPatch.AddRemainQuota
|
cleanToken.RemainQuota += tokenPatch.AddRemainQuota
|
||||||
cleanToken.UsedQuota += tokenPatch.AddUsedQuota
|
cleanToken.UsedQuota += tokenPatch.AddUsedQuota
|
||||||
|
|
||||||
|
if tokenPatch.AddUsedQuota != 0 {
|
||||||
|
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{
|
||||||
"success": false,
|
"success": false,
|
||||||
|
Loading…
Reference in New Issue
Block a user