feat: able to display quota in dollar

This commit is contained in:
JustSong
2023-06-20 20:09:17 +08:00
parent 3d76a974d1
commit b179c2f208
19 changed files with 125 additions and 45 deletions

View File

@@ -2,6 +2,7 @@ package controller
import (
"github.com/gin-gonic/gin"
"one-api/common"
"one-api/model"
)
@@ -18,23 +19,38 @@ func GetSubscription(c *gin.Context) {
})
return
}
amount := float64(quota)
if common.DisplayInCurrencyEnabled {
amount /= common.QuotaPerUnit
}
subscription := OpenAISubscriptionResponse{
Object: "billing_subscription",
HasPaymentMethod: true,
SoftLimitUSD: float64(quota),
HardLimitUSD: float64(quota),
SystemHardLimitUSD: float64(quota),
SoftLimitUSD: amount,
HardLimitUSD: amount,
SystemHardLimitUSD: amount,
}
c.JSON(200, subscription)
return
}
func GetUsage(c *gin.Context) {
//userId := c.GetInt("id")
// TODO: get usage from database
userId := c.GetInt("id")
quota, err := model.GetUserUsedQuota(userId)
if err != nil {
openAIError := OpenAIError{
Message: err.Error(),
Type: "one_api_error",
}
c.JSON(200, gin.H{
"error": openAIError,
})
return
}
amount := float64(quota)
usage := OpenAIUsageResponse{
Object: "list",
TotalUsage: 0,
TotalUsage: amount,
}
c.JSON(200, usage)
return