feat: add access_until field for subscription api (#295)
* 支持从计费渠道端点返回日期 * fix: fix wrong git base --------- Co-authored-by: JustSong <songquanpeng@foxmail.com>
This commit is contained in:
parent
2fcd6852e0
commit
dccd66b852
@ -11,9 +11,11 @@ func GetSubscription(c *gin.Context) {
|
|||||||
var usedQuota int
|
var usedQuota int
|
||||||
var err error
|
var err error
|
||||||
var token *model.Token
|
var token *model.Token
|
||||||
|
var expiredTime int64
|
||||||
if common.DisplayTokenStatEnabled {
|
if common.DisplayTokenStatEnabled {
|
||||||
tokenId := c.GetInt("token_id")
|
tokenId := c.GetInt("token_id")
|
||||||
token, err = model.GetTokenById(tokenId)
|
token, err = model.GetTokenById(tokenId)
|
||||||
|
expiredTime = token.ExpiredTime
|
||||||
remainQuota = token.RemainQuota
|
remainQuota = token.RemainQuota
|
||||||
usedQuota = token.UsedQuota
|
usedQuota = token.UsedQuota
|
||||||
} else {
|
} else {
|
||||||
@ -21,6 +23,9 @@ func GetSubscription(c *gin.Context) {
|
|||||||
remainQuota, err = model.GetUserQuota(userId)
|
remainQuota, err = model.GetUserQuota(userId)
|
||||||
usedQuota, err = model.GetUserUsedQuota(userId)
|
usedQuota, err = model.GetUserUsedQuota(userId)
|
||||||
}
|
}
|
||||||
|
if expiredTime <= 0 {
|
||||||
|
expiredTime = 0
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
openAIError := OpenAIError{
|
openAIError := OpenAIError{
|
||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
@ -45,6 +50,7 @@ func GetSubscription(c *gin.Context) {
|
|||||||
SoftLimitUSD: amount,
|
SoftLimitUSD: amount,
|
||||||
HardLimitUSD: amount,
|
HardLimitUSD: amount,
|
||||||
SystemHardLimitUSD: amount,
|
SystemHardLimitUSD: amount,
|
||||||
|
AccessUntil: expiredTime,
|
||||||
}
|
}
|
||||||
c.JSON(200, subscription)
|
c.JSON(200, subscription)
|
||||||
return
|
return
|
||||||
|
@ -22,6 +22,7 @@ type OpenAISubscriptionResponse struct {
|
|||||||
SoftLimitUSD float64 `json:"soft_limit_usd"`
|
SoftLimitUSD float64 `json:"soft_limit_usd"`
|
||||||
HardLimitUSD float64 `json:"hard_limit_usd"`
|
HardLimitUSD float64 `json:"hard_limit_usd"`
|
||||||
SystemHardLimitUSD float64 `json:"system_hard_limit_usd"`
|
SystemHardLimitUSD float64 `json:"system_hard_limit_usd"`
|
||||||
|
AccessUntil int64 `json:"access_until"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OpenAIUsageDailyCost struct {
|
type OpenAIUsageDailyCost struct {
|
||||||
@ -96,6 +97,9 @@ func GetResponseBody(method, url string, channel *model.Channel, headers http.He
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if res.StatusCode != http.StatusOK {
|
||||||
|
return nil, fmt.Errorf("status code: %d", res.StatusCode)
|
||||||
|
}
|
||||||
body, err := io.ReadAll(res.Body)
|
body, err := io.ReadAll(res.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user