fix(pool): align status filters with visible key state

This commit is contained in:
cym
2026-05-30 18:49:26 +08:00
parent 0d76a8e478
commit ce1d532e3c
6 changed files with 351 additions and 46 deletions
@@ -943,6 +943,10 @@ fn admin_pool_scheduling_payload(
account_status_reason: Option<&str>,
account_status_source: Option<&str>,
account_quota_exhausted: bool,
oauth_status_code: Option<&str>,
oauth_status_label: Option<&str>,
oauth_status_reason: Option<&str>,
oauth_status_source: Option<&str>,
) -> (String, String, String, Vec<serde_json::Value>) {
if !key.is_active {
return (
@@ -989,6 +993,26 @@ fn admin_pool_scheduling_payload(
})],
);
}
if matches!(oauth_status_code, Some("invalid" | "expired")) {
let label = oauth_status_label.unwrap_or(if oauth_status_code == Some("expired") {
"已过期"
} else {
"已失效"
});
return (
"blocked".to_string(),
oauth_status_code.unwrap_or("invalid").to_string(),
label.to_string(),
vec![json!({
"code": oauth_status_code.unwrap_or("invalid"),
"label": label,
"blocking": true,
"source": oauth_status_source.unwrap_or("oauth"),
"ttl_seconds": serde_json::Value::Null,
"detail": oauth_status_reason,
})],
);
}
if let Some(reason) = cooldown_reason {
return (
"degraded".to_string(),
@@ -1105,6 +1129,13 @@ pub(super) fn build_admin_pool_key_payload(
.unwrap_or(false);
let account_status_source =
admin_pool_trimmed_string(account_snapshot.and_then(|item| item.get("source")));
let oauth_status_code = admin_pool_trimmed_string_from_map(oauth_snapshot, "code");
let oauth_status_label =
admin_pool_trimmed_string(oauth_snapshot.and_then(|item| item.get("label")));
let oauth_status_reason =
admin_pool_trimmed_string(oauth_snapshot.and_then(|item| item.get("reason")));
let oauth_status_source =
admin_pool_trimmed_string(oauth_snapshot.and_then(|item| item.get("source")));
let (scheduling_status, scheduling_reason, scheduling_label, scheduling_reasons) =
admin_pool_scheduling_payload(
key,
@@ -1116,6 +1147,10 @@ pub(super) fn build_admin_pool_key_payload(
account_status_reason.as_deref(),
account_status_source.as_deref(),
account_quota_exhausted,
oauth_status_code.as_deref(),
oauth_status_label.as_deref(),
oauth_status_reason.as_deref(),
oauth_status_source.as_deref(),
);
let mut payload = serde_json::Map::new();