feat: show chatgpt web image quota

This commit is contained in:
Codex
2026-05-06 22:58:47 +08:00
parent 7eaf3e7d03
commit 41f75a3f19
21 changed files with 1801 additions and 16 deletions
@@ -481,6 +481,43 @@ fn admin_pool_build_kiro_account_quota_from_snapshot(
}
}
fn admin_pool_build_chatgpt_web_account_quota_from_snapshot(
quota_snapshot: &serde_json::Map<String, serde_json::Value>,
) -> Option<String> {
let now_unix_secs = chrono::Utc::now().timestamp().max(0) as u64;
let window = admin_pool_quota_window(quota_snapshot, "image_gen")
.or_else(|| admin_pool_quota_windows(quota_snapshot).into_iter().next())?;
let remaining_value = admin_pool_json_to_f64(window.get("remaining_value"));
let limit_value = admin_pool_json_to_f64(window.get("limit_value"));
let remaining_percent = admin_pool_json_to_f64(window.get("remaining_ratio"))
.map(|value| (value * 100.0).clamp(0.0, 100.0))
.or_else(|| {
admin_pool_json_to_f64(window.get("used_ratio"))
.map(|value| ((1.0 - value) * 100.0).clamp(0.0, 100.0))
});
let reset_seconds =
admin_pool_quota_window_reset_seconds(quota_snapshot, window, now_unix_secs);
let mut text = match (remaining_value, limit_value, remaining_percent) {
(Some(remaining), Some(limit), _) if limit > 0.0 => Some(format!(
"生图剩余 {}/{}",
admin_pool_format_quota_value(remaining),
admin_pool_format_quota_value(limit),
)),
(Some(remaining), _, _) => Some(format!(
"生图剩余 {}",
admin_pool_format_quota_value(remaining),
)),
(_, _, Some(percent)) => Some(format!("生图剩余 {}", admin_pool_format_percent(percent))),
_ => None,
}?;
if let Some(reset_text) = reset_seconds.and_then(admin_pool_format_reset_after) {
text.push_str(&format!(" ({reset_text})"));
}
Some(text)
}
fn admin_pool_build_antigravity_account_quota_from_snapshot(
quota_snapshot: &serde_json::Map<String, serde_json::Value>,
) -> Option<String> {
@@ -617,6 +654,13 @@ fn admin_pool_build_account_quota(
return Some(account_quota);
}
}
"chatgpt_web" => {
if let Some(account_quota) =
admin_pool_build_chatgpt_web_account_quota_from_snapshot(quota_snapshot)
{
return Some(account_quota);
}
}
"antigravity" => {
if let Some(account_quota) =
admin_pool_build_antigravity_account_quota_from_snapshot(quota_snapshot)