mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-10-15 07:20:26 +00:00
feat: able to set initial quota for new user (close #22)
This commit is contained in:
@@ -104,6 +104,19 @@ func AddToken(c *gin.Context) {
|
||||
if isAdmin {
|
||||
cleanToken.RemainTimes = token.RemainTimes
|
||||
cleanToken.UnlimitedTimes = token.UnlimitedTimes
|
||||
} else {
|
||||
userId := c.GetInt("id")
|
||||
quota, err := model.GetUserQuota(userId)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": false,
|
||||
"message": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
if quota > 0 {
|
||||
cleanToken.RemainTimes = quota
|
||||
}
|
||||
}
|
||||
err = cleanToken.Insert()
|
||||
if err != nil {
|
||||
@@ -113,6 +126,10 @@ func AddToken(c *gin.Context) {
|
||||
})
|
||||
return
|
||||
}
|
||||
if !isAdmin {
|
||||
// update user quota
|
||||
err = model.DecreaseUserQuota(c.GetInt("id"), cleanToken.RemainTimes)
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": true,
|
||||
"message": "",
|
||||
|
Reference in New Issue
Block a user