billing.go 823 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package controller
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "one-api/model"
  5. )
  6. func GetSubscription(c *gin.Context) {
  7. userId := c.GetInt("id")
  8. quota, err := model.GetUserQuota(userId)
  9. if err != nil {
  10. openAIError := OpenAIError{
  11. Message: err.Error(),
  12. Type: "one_api_error",
  13. }
  14. c.JSON(200, gin.H{
  15. "error": openAIError,
  16. })
  17. return
  18. }
  19. subscription := OpenAISubscriptionResponse{
  20. Object: "billing_subscription",
  21. HasPaymentMethod: true,
  22. SoftLimitUSD: float64(quota),
  23. HardLimitUSD: float64(quota),
  24. SystemHardLimitUSD: float64(quota),
  25. }
  26. c.JSON(200, subscription)
  27. return
  28. }
  29. func GetUsage(c *gin.Context) {
  30. //userId := c.GetInt("id")
  31. // TODO: get usage from database
  32. usage := OpenAIUsageResponse{
  33. Object: "list",
  34. TotalUsage: 0,
  35. }
  36. c.JSON(200, usage)
  37. return
  38. }