diff --git a/controller/billing.go b/controller/billing.go index a45253ab..933938d1 100644 --- a/controller/billing.go +++ b/controller/billing.go @@ -1,18 +1,24 @@ package controller import ( - "github.com/gin-gonic/gin" "one-api/common" "one-api/model" + "time" + + "github.com/gin-gonic/gin" ) func GetSubscription(c *gin.Context) { var quota int var err error - var token *model.Token + var expirationDate int64 + + tokenId := c.GetInt("token_id") + token, err := model.GetTokenById(tokenId) + + expirationDate = token.ExpiredTime + if common.DisplayTokenStatEnabled { - tokenId := c.GetInt("token_id") - token, err = model.GetTokenById(tokenId) quota = token.RemainQuota } else { userId := c.GetInt("id") @@ -41,6 +47,7 @@ func GetSubscription(c *gin.Context) { SoftLimitUSD: amount, HardLimitUSD: amount, SystemHardLimitUSD: amount, + AccessUntil: time.Unix(expirationDate, 0), } c.JSON(200, subscription) return diff --git a/controller/channel-billing.go b/controller/channel-billing.go index 3621b012..474c69b3 100644 --- a/controller/channel-billing.go +++ b/controller/channel-billing.go @@ -17,11 +17,12 @@ import ( // https://github.com/songquanpeng/one-api/issues/79 type OpenAISubscriptionResponse struct { - Object string `json:"object"` - HasPaymentMethod bool `json:"has_payment_method"` - SoftLimitUSD float64 `json:"soft_limit_usd"` - HardLimitUSD float64 `json:"hard_limit_usd"` - SystemHardLimitUSD float64 `json:"system_hard_limit_usd"` + Object string `json:"object"` + HasPaymentMethod bool `json:"has_payment_method"` + SoftLimitUSD float64 `json:"soft_limit_usd"` + HardLimitUSD float64 `json:"hard_limit_usd"` + SystemHardLimitUSD float64 `json:"system_hard_limit_usd"` + AccessUntil time.Time `json:"access_until"` } type OpenAIUsageDailyCost struct { diff --git a/controller/channel-test.go b/controller/channel-test.go index 4ec00e1e..feb212b2 100644 --- a/controller/channel-test.go +++ b/controller/channel-test.go @@ -6,7 +6,7 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" + "io" "net/http" "one-api/common" "one-api/model" @@ -100,7 +100,7 @@ func testChannel(channel *model.Channel, request ChatRequest) error { } } } else { - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return err } diff --git a/controller/relay-text.go b/controller/relay-text.go index eab71a95..401b701f 100644 --- a/controller/relay-text.go +++ b/controller/relay-text.go @@ -6,12 +6,14 @@ import ( "encoding/json" "errors" "fmt" - "github.com/gin-gonic/gin" "io" + "log" "net/http" "one-api/common" "one-api/model" "strings" + + "github.com/gin-gonic/gin" ) func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode { @@ -157,6 +159,19 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode { if err != nil { return errorWrapper(err, "do_request_failed", http.StatusInternalServerError) } + if resp.StatusCode != http.StatusOK { + // Print Data if Error + bodyBytes, err := io.ReadAll(resp.Body) + if err != nil { + return errorWrapper(err, "read_response_body_failed", http.StatusInternalServerError) + } + + bodyString := string(bodyBytes) + + log.Printf("Error: %s", bodyString) + + return errorWrapper(err, "request_failed", resp.StatusCode) + } err = req.Body.Close() if err != nil { return errorWrapper(err, "close_request_body_failed", http.StatusInternalServerError)