MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / GetSubscription

Function GetSubscription

controller/billing.go:10–58  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

8)
9
10func 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
60func GetUsage(c *gin.Context) {
61 var quota int

Callers

nothing calls this directly

Calls 4

GetTokenByIdFunction · 0.92
GetUserQuotaFunction · 0.92
GetUserUsedQuotaFunction · 0.92
ErrorMethod · 0.80

Tested by

no test coverage detected