(c *gin.Context)
| 8 | ) |
| 9 | |
| 10 | func GetSubscription(c *gin.Context) { |
| 11 | var remainQuota int |
| 12 | var usedQuota int |
| 13 | var err error |
| 14 | var token *model.Token |
| 15 | var expiredTime int64 |
| 16 | if common.DisplayTokenStatEnabled { |
| 17 | tokenId := c.GetInt("token_id") |
| 18 | token, err = model.GetTokenById(tokenId) |
| 19 | expiredTime = token.ExpiredTime |
| 20 | remainQuota = token.RemainQuota |
| 21 | usedQuota = token.UsedQuota |
| 22 | } else { |
| 23 | userId := c.GetInt("id") |
| 24 | remainQuota, err = model.GetUserQuota(userId, false) |
| 25 | usedQuota, err = model.GetUserUsedQuota(userId) |
| 26 | } |
| 27 | if expiredTime <= 0 { |
| 28 | expiredTime = 0 |
| 29 | } |
| 30 | if err != nil { |
| 31 | openAIError := dto.OpenAIError{ |
| 32 | Message: err.Error(), |
| 33 | Type: "upstream_error", |
| 34 | } |
| 35 | c.JSON(200, gin.H{ |
| 36 | "error": openAIError, |
| 37 | }) |
| 38 | return |
| 39 | } |
| 40 | quota := remainQuota + usedQuota |
| 41 | amount := float64(quota) |
| 42 | if common.DisplayInCurrencyEnabled { |
| 43 | amount /= common.QuotaPerUnit |
| 44 | } |
| 45 | if token != nil && token.UnlimitedQuota { |
| 46 | amount = 100000000 |
| 47 | } |
| 48 | subscription := OpenAISubscriptionResponse{ |
| 49 | Object: "billing_subscription", |
| 50 | HasPaymentMethod: true, |
| 51 | SoftLimitUSD: amount, |
| 52 | HardLimitUSD: amount, |
| 53 | SystemHardLimitUSD: amount, |
| 54 | AccessUntil: expiredTime, |
| 55 | } |
| 56 | c.JSON(200, subscription) |
| 57 | return |
| 58 | } |
| 59 | |
| 60 | func GetUsage(c *gin.Context) { |
| 61 | var quota int |
nothing calls this directly
no test coverage detected