+10
-1
@@ -7,6 +7,12 @@ function percent(value: number) {
|
||||
return value < 0.1 && value > 0 ? "<0.1" : value.toFixed(value < 10 ? 1 : 0);
|
||||
}
|
||||
|
||||
function duration(seconds: number) {
|
||||
if (seconds % 86_400 === 0) return `${seconds / 86_400}d`;
|
||||
if (seconds % 3_600 === 0) return `${seconds / 3_600}h`;
|
||||
return `${Math.round(seconds / 60)}m`;
|
||||
}
|
||||
|
||||
function resetTiming(resetsAt: number, now: number) {
|
||||
if (!Number.isFinite(resetsAt) || resetsAt <= 0 || !Number.isFinite(now)) return "unavailable";
|
||||
const remaining = resetsAt - now;
|
||||
@@ -31,7 +37,10 @@ export function formatQuotaWindow(
|
||||
window: QuotaWindow & { remaining: number; sessionConsumed: number },
|
||||
now = Date.now(),
|
||||
) {
|
||||
return `${percent(window.remaining)}% · ~${percent(window.sessionConsumed)}pp · ${resetTiming(window.resetsAt, now)}`;
|
||||
const label = window.label
|
||||
? `${window.label} ${duration(window.seconds)}`
|
||||
: duration(window.seconds);
|
||||
return `${label}: ${percent(window.remaining)}% · ~${percent(window.sessionConsumed)}pp · ${resetTiming(window.resetsAt, now)}`;
|
||||
}
|
||||
|
||||
export async function loadQuotaStatus(load: () => Promise<QuotaStatus | null>) {
|
||||
|
||||
Reference in New Issue
Block a user