-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusage-credits.js
More file actions
62 lines (55 loc) · 1.85 KB
/
Copy pathusage-credits.js
File metadata and controls
62 lines (55 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
({
request: {
url: "https://api.commandcode.ai/alpha/billing/credits",
method: "GET",
headers: {
"Authorization": "Bearer {{apiKey}}"
}
},
extractor: function(response) {
if (response.windowLimits) {
const fh = response.windowLimits.fiveHour;
const wk = response.windowLimits.weekly;
const credits = response.credits;
// ⚠️ 手动维护:修改为你套餐的月度额度
// GOAT=70, Pro=30, Max=150, Ultra=300, Teams Pro=40
const monthlyCap = 70;
const monthlyUsed = monthlyCap - credits.monthlyCredits;
const pct = function(used, cap) {
return Math.round((used / cap) * 100) + "%";
};
const reset = function(ts) {
if (!ts) return "";
const diff = ts - Date.now();
if (diff <= 0) return "已重置";
const d = Math.floor(diff / 86400000);
const h = Math.floor((diff % 86400000) / 3600000);
const m = Math.floor((diff % 3600000) / 60000);
if (d > 0) return d + "d" + h + "h";
if (h > 0) return h + "h" + m + "m";
return m + "m";
};
let line1 = [];
let line2 = [];
if (fh) {
line1.push("5h " + pct(fh.used, fh.cap));
line2.push("5h reset in " + reset(fh.resetAt));
}
if (wk) {
line1.push("7d " + pct(wk.used, wk.cap));
line2.push("7d reset in " + reset(wk.resetAt));
}
line1.push("月 " + pct(monthlyUsed, monthlyCap));
line2.push("余额 $" + credits.monthlyCredits.toFixed(2));
return {
isValid: true,
remaining: credits.monthlyCredits,
total: monthlyCap,
unit: "credits",
planName: "GOAT",
extra: line1.join(" · ") + "\n" + line2.join(" · ")
};
}
return { isValid: false, invalidMessage: "查询失败" };
}
})