mirror of
https://github.com/zgs225/cliproxy-plugin-commandcode.git
synced 2026-09-26 03:32:50 +08:00
feat: derive monthly (billing period) usage window
- Add FetchUsageSummaryRaw calling /internal/usage/summary which returns billing-period totals (periodBasis=billing-period) - Derive monthly window: used=totalMonthlyCredits, cap=totalMonthlyCredits + monthlyCredits remaining (≈ plan monthly total), remaining=monthlyCredits - Add monthly card to quota resource page (HTML + JS rendering) - Skip monthly card when summary unavailable
This commit is contained in:
+10
-1
@@ -182,7 +182,16 @@ func executeUsageQuery(ctx context.Context, apiBase, sessionToken, hostCallbackI
|
||||
}, nil
|
||||
}
|
||||
|
||||
usage, errParse := ParseAndFormatUsage(raw, time.Now().UTC())
|
||||
// Fetch billing-period (monthly) usage totals; non-fatal if unavailable.
|
||||
var summary *UpstreamUsageSummaryResponse
|
||||
if sumRaw, sumStatus, sumErr := FetchUsageSummaryRaw(ctx, apiBase, sessionToken, hostCallbackID); sumErr == nil && sumStatus == http.StatusOK {
|
||||
var parsed UpstreamUsageSummaryResponse
|
||||
if errSum := json.Unmarshal(sumRaw, &parsed); errSum == nil && parsed.TotalMonthlyCredits > 0 {
|
||||
summary = &parsed
|
||||
}
|
||||
}
|
||||
|
||||
usage, errParse := ParseAndFormatUsage(raw, summary, time.Now().UTC())
|
||||
if errParse != nil {
|
||||
resBytes, _ := json.Marshal(map[string]any{
|
||||
"ok": false,
|
||||
|
||||
Reference in New Issue
Block a user