mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-10-18 01:16:05 +00:00
feat: able to display token billing stat via billing api (close #186)
This commit is contained in:
@@ -7,8 +7,17 @@ import (
|
||||
)
|
||||
|
||||
func GetSubscription(c *gin.Context) {
|
||||
userId := c.GetInt("id")
|
||||
quota, err := model.GetUserQuota(userId)
|
||||
var quota int
|
||||
var err error
|
||||
var token *model.Token
|
||||
if common.DisplayTokenStatEnabled {
|
||||
tokenId := c.GetInt("token_id")
|
||||
token, err = model.GetTokenById(tokenId)
|
||||
quota = token.RemainQuota
|
||||
} else {
|
||||
userId := c.GetInt("id")
|
||||
quota, err = model.GetUserQuota(userId)
|
||||
}
|
||||
if err != nil {
|
||||
openAIError := OpenAIError{
|
||||
Message: err.Error(),
|
||||
@@ -35,8 +44,17 @@ func GetSubscription(c *gin.Context) {
|
||||
}
|
||||
|
||||
func GetUsage(c *gin.Context) {
|
||||
userId := c.GetInt("id")
|
||||
quota, err := model.GetUserUsedQuota(userId)
|
||||
var quota int
|
||||
var err error
|
||||
var token *model.Token
|
||||
if common.DisplayTokenStatEnabled {
|
||||
tokenId := c.GetInt("token_id")
|
||||
token, err = model.GetTokenById(tokenId)
|
||||
quota = token.UsedQuota
|
||||
} else {
|
||||
userId := c.GetInt("id")
|
||||
quota, err = model.GetUserUsedQuota(userId)
|
||||
}
|
||||
if err != nil {
|
||||
openAIError := OpenAIError{
|
||||
Message: err.Error(),
|
||||
|
Reference in New Issue
Block a user