Skip to content

Commit

Permalink
chore: make subscription api compatible with official api
Browse files Browse the repository at this point in the history
  • Loading branch information
songquanpeng committed Jul 15, 2023
1 parent 02da0b5 commit 4139a70
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions controller/billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ import (
)

func GetSubscription(c *gin.Context) {
var quota int
var remainQuota int
var usedQuota int
var err error
var token *model.Token
if common.DisplayTokenStatEnabled {
tokenId := c.GetInt("token_id")
token, err = model.GetTokenById(tokenId)
quota = token.RemainQuota
remainQuota = token.RemainQuota
usedQuota = token.UsedQuota
} else {
userId := c.GetInt("id")
quota, err = model.GetUserQuota(userId)
remainQuota, err = model.GetUserQuota(userId)
usedQuota, err = model.GetUserUsedQuota(userId)
}
if err != nil {
openAIError := OpenAIError{
Expand All @@ -28,6 +31,7 @@ func GetSubscription(c *gin.Context) {
})
return
}
quota := remainQuota + usedQuota
amount := float64(quota)
if common.DisplayInCurrencyEnabled {
amount /= common.QuotaPerUnit
Expand Down

0 comments on commit 4139a70

Please sign in to comment.