feat(ccswitch): 添加一键导入和用量查询

This commit is contained in:
Entropy.Xu
2026-05-29 21:39:45 +08:00
parent 0d76a8e478
commit 7ed4b84654
23 changed files with 1720 additions and 48 deletions
@@ -195,6 +195,9 @@ fn select_primary_credential(
if signature.starts_with("openai:") {
return select_openai_credential(bundle);
}
if signature.starts_with("aether:") {
return select_openai_credential(bundle);
}
select_generic_credential(bundle)
}
@@ -826,8 +826,9 @@ async fn build_data_backed_auth_context(
.map(|(provider, _)| provider)
.unwrap_or(auth_endpoint_signature)
.trim();
let requested_provider_allowed =
auth_snapshot_allows_requested_provider(state, &snapshot, auth_endpoint_signature).await;
let identity_only = auth_gate_identity_only(auth_endpoint_signature);
let requested_provider_allowed = identity_only
|| auth_snapshot_allows_requested_provider(state, &snapshot, auth_endpoint_signature).await;
let local_rejection = if invalid_api_key {
Some(GatewayLocalAuthRejection::InvalidApiKey)
} else if locked_api_key {
@@ -845,14 +846,15 @@ async fn build_data_backed_auth_context(
Some(GatewayLocalAuthRejection::ProviderNotAllowed {
provider: requested_provider.to_string(),
})
} else if snapshot
.effective_allowed_api_formats()
.is_some_and(|allowed| {
!contains_api_format_or_alias(
allowed,
auth_gate_api_format(auth_endpoint_signature).as_str(),
)
})
} else if !identity_only
&& snapshot
.effective_allowed_api_formats()
.is_some_and(|allowed| {
!contains_api_format_or_alias(
allowed,
auth_gate_api_format(auth_endpoint_signature).as_str(),
)
})
{
Some(GatewayLocalAuthRejection::ApiFormatNotAllowed {
api_format: auth_endpoint_signature.to_string(),
@@ -896,6 +898,13 @@ fn auth_gate_api_format(auth_endpoint_signature: &str) -> String {
}
}
fn auth_gate_identity_only(auth_endpoint_signature: &str) -> bool {
matches!(
auth_endpoint_signature.trim().to_ascii_lowercase().as_str(),
"aether:ccswitch_usage"
)
}
fn api_format_matches(left: &str, right: &str) -> bool {
aether_scheduler_core::api_format_matches_allowed_value(left, right)
}