Merge pull request #3 from hkxiaoyao/main
feat(account): add trial quota tracking and display
This commit is contained in:
@@ -1267,15 +1267,20 @@ func (h *Handler) apiGetAccounts(w http.ResponseWriter, r *http.Request) {
|
||||
"expiresAt": a.ExpiresAt,
|
||||
"hasToken": a.AccessToken != "",
|
||||
"machineId": a.MachineId,
|
||||
"subscriptionType": a.SubscriptionType,
|
||||
"subscriptionTitle": a.SubscriptionTitle,
|
||||
"daysRemaining": a.DaysRemaining,
|
||||
"usageCurrent": a.UsageCurrent,
|
||||
"usageLimit": a.UsageLimit,
|
||||
"usagePercent": a.UsagePercent,
|
||||
"nextResetDate": a.NextResetDate,
|
||||
"lastRefresh": a.LastRefresh,
|
||||
"requestCount": stats.RequestCount,
|
||||
"subscriptionType": a.SubscriptionType,
|
||||
"subscriptionTitle": a.SubscriptionTitle,
|
||||
"daysRemaining": a.DaysRemaining,
|
||||
"usageCurrent": a.UsageCurrent,
|
||||
"usageLimit": a.UsageLimit,
|
||||
"usagePercent": a.UsagePercent,
|
||||
"nextResetDate": a.NextResetDate,
|
||||
"lastRefresh": a.LastRefresh,
|
||||
"trialUsageCurrent": a.TrialUsageCurrent,
|
||||
"trialUsageLimit": a.TrialUsageLimit,
|
||||
"trialUsagePercent": a.TrialUsagePercent,
|
||||
"trialStatus": a.TrialStatus,
|
||||
"trialExpiresAt": a.TrialExpiresAt,
|
||||
"requestCount": stats.RequestCount,
|
||||
"errorCount": stats.ErrorCount,
|
||||
"totalTokens": stats.TotalTokens,
|
||||
"totalCredits": stats.TotalCredits,
|
||||
|
||||
@@ -186,6 +186,28 @@ func RefreshAccountInfo(account *config.Account) (*config.AccountInfo, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// 解析试用配额信息
|
||||
if len(usage.UsageBreakdownList) > 0 {
|
||||
breakdown := usage.UsageBreakdownList[0]
|
||||
if breakdown.FreeTrialInfo != nil {
|
||||
info.TrialUsageCurrent = breakdown.FreeTrialInfo.CurrentUsage
|
||||
info.TrialUsageLimit = breakdown.FreeTrialInfo.UsageLimit
|
||||
if info.TrialUsageLimit > 0 {
|
||||
info.TrialUsagePercent = info.TrialUsageCurrent / info.TrialUsageLimit
|
||||
}
|
||||
info.TrialStatus = breakdown.FreeTrialInfo.FreeTrialStatus
|
||||
|
||||
// 解析试用到期时间
|
||||
if breakdown.FreeTrialInfo.FreeTrialExpiry != "" {
|
||||
if ts, err := breakdown.FreeTrialInfo.FreeTrialExpiry.Int64(); err == nil && ts > 0 {
|
||||
info.TrialExpiresAt = ts
|
||||
} else if f, err := breakdown.FreeTrialInfo.FreeTrialExpiry.Float64(); err == nil && f > 0 {
|
||||
info.TrialExpiresAt = int64(f)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return info, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user