feat: able to display token billing stat via billing api (close #186)

This commit is contained in:
JustSong
2023-06-23 20:14:53 +08:00
parent d4869dfad2
commit 7edc2b5376
6 changed files with 49 additions and 9 deletions

View File

@@ -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(),

View File

@@ -13,7 +13,7 @@ func GetOptions(c *gin.Context) {
var options []*model.Option
common.OptionMapRWMutex.Lock()
for k, v := range common.OptionMap {
if strings.Contains(k, "Token") || strings.Contains(k, "Secret") {
if strings.HasSuffix(k, "Token") || strings.HasSuffix(k, "Secret") {
continue
}
options = append(options, &model.Option{