mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 01:10:23 +08:00
fix(clippy): 修复冗余 into_iter、sort_by 及 match 嵌套 if 等 lint 警告
This commit is contained in:
@@ -251,7 +251,7 @@ async fn list_admin_monitoring_cache_affinity_records_matching(
|
|||||||
"admin monitoring redis mget failed: {err}"
|
"admin monitoring redis mget failed: {err}"
|
||||||
))
|
))
|
||||||
})?;
|
})?;
|
||||||
for (key, raw_value) in keys.into_iter().zip(values.into_iter()) {
|
for (key, raw_value) in keys.into_iter().zip(values) {
|
||||||
let Some(raw_value) = raw_value else {
|
let Some(raw_value) = raw_value else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -157,8 +157,7 @@ pub(super) async fn build_admin_monitoring_resilience_snapshot(
|
|||||||
limit: None,
|
limit: None,
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
recent_usage_errors
|
recent_usage_errors.sort_by_key(|item| std::cmp::Reverse(item.created_at_unix_ms));
|
||||||
.sort_by(|left, right| right.created_at_unix_ms.cmp(&left.created_at_unix_ms));
|
|
||||||
|
|
||||||
let total_errors = recent_usage_errors.len();
|
let total_errors = recent_usage_errors.len();
|
||||||
let mut error_breakdown = BTreeMap::<String, usize>::new();
|
let mut error_breakdown = BTreeMap::<String, usize>::new();
|
||||||
|
|||||||
@@ -263,11 +263,11 @@ pub(super) fn build_admin_provider_oauth_batch_task_state(
|
|||||||
.ok()
|
.ok()
|
||||||
.map(|duration| duration.as_secs())
|
.map(|duration| duration.as_secs())
|
||||||
.unwrap_or(created_at);
|
.unwrap_or(created_at);
|
||||||
let progress_percent = if total == 0 {
|
let progress_percent = processed
|
||||||
0
|
.saturating_mul(100)
|
||||||
} else {
|
.checked_div(total)
|
||||||
((processed * 100) / total).min(100) as u64
|
.unwrap_or(0)
|
||||||
};
|
.min(100) as u64;
|
||||||
json!({
|
json!({
|
||||||
"task_id": task_id,
|
"task_id": task_id,
|
||||||
"provider_id": provider_id,
|
"provider_id": provider_id,
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ pub(crate) async fn read_admin_provider_pool_cooldown_counts(
|
|||||||
Ok(counts) => provider_ids
|
Ok(counts) => provider_ids
|
||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.zip(counts.into_iter())
|
.zip(counts)
|
||||||
.map(|(provider_id, count)| (provider_id, count as usize))
|
.map(|(provider_id, count)| (provider_id, count as usize))
|
||||||
.collect(),
|
.collect(),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -155,8 +155,8 @@ pub(crate) async fn read_admin_provider_pool_runtime_state(
|
|||||||
for (((key_id, _cooldown_key), reason), ttl) in key_ids
|
for (((key_id, _cooldown_key), reason), ttl) in key_ids
|
||||||
.iter()
|
.iter()
|
||||||
.zip(cooldown_keys.iter())
|
.zip(cooldown_keys.iter())
|
||||||
.zip(cooldown_reasons.into_iter())
|
.zip(cooldown_reasons)
|
||||||
.zip(cooldown_ttls.into_iter())
|
.zip(cooldown_ttls)
|
||||||
{
|
{
|
||||||
if let Some(reason) = reason {
|
if let Some(reason) = reason {
|
||||||
runtime
|
runtime
|
||||||
@@ -197,7 +197,7 @@ pub(crate) async fn read_admin_provider_pool_runtime_state(
|
|||||||
);
|
);
|
||||||
vec![Vec::new(); cost_keys.len()]
|
vec![Vec::new(); cost_keys.len()]
|
||||||
});
|
});
|
||||||
for (key_id, members) in key_ids.iter().zip(members_by_key.into_iter()) {
|
for (key_id, members) in key_ids.iter().zip(members_by_key) {
|
||||||
let total = members
|
let total = members
|
||||||
.iter()
|
.iter()
|
||||||
.map(|member| parse_pool_cost_member(member))
|
.map(|member| parse_pool_cost_member(member))
|
||||||
@@ -218,7 +218,7 @@ pub(crate) async fn read_admin_provider_pool_runtime_state(
|
|||||||
.query_async::<Vec<Option<f64>>>(&mut connection)
|
.query_async::<Vec<Option<f64>>>(&mut connection)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
for (key_id, score) in key_ids.iter().zip(scores.into_iter()) {
|
for (key_id, score) in key_ids.iter().zip(scores) {
|
||||||
if let Some(score) = score {
|
if let Some(score) = score {
|
||||||
runtime.lru_score_by_key.insert(key_id.clone(), score);
|
runtime.lru_score_by_key.insert(key_id.clone(), score);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ async fn provider_query_sort_antigravity_keys(
|
|||||||
};
|
};
|
||||||
ranked.push(((availability, tier_weight), key));
|
ranked.push(((availability, tier_weight), key));
|
||||||
}
|
}
|
||||||
ranked.sort_by(|left, right| right.0.cmp(&left.0));
|
ranked.sort_by_key(|entry| std::cmp::Reverse(entry.0));
|
||||||
Ok(ranked.into_iter().map(|(_, key)| key).collect())
|
Ok(ranked.into_iter().map(|(_, key)| key).collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,20 +38,14 @@ pub(crate) async fn build_admin_create_provider_key_record(
|
|||||||
.cloned();
|
.cloned();
|
||||||
|
|
||||||
match auth_type.as_str() {
|
match auth_type.as_str() {
|
||||||
"api_key" => {
|
"api_key" if api_key.is_empty() => {
|
||||||
if api_key.is_empty() {
|
return Err("API Key 认证模式下 api_key 为必填字段".to_string());
|
||||||
return Err("API Key 认证模式下 api_key 为必填字段".to_string());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
"service_account" => {
|
"service_account" if auth_config_object.is_none() => {
|
||||||
if auth_config_object.is_none() {
|
return Err("Service Account 认证模式下 auth_config 为必填字段".to_string());
|
||||||
return Err("Service Account 认证模式下 auth_config 为必填字段".to_string());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
"oauth" => {
|
"oauth" if !api_key.is_empty() => {
|
||||||
if !api_key.is_empty() {
|
return Err("OAuth 认证模式下不允许直接填写 api_key".to_string());
|
||||||
return Err("OAuth 认证模式下不允许直接填写 api_key".to_string());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ fn set_cached_fingerprint(key_id: &str, fingerprint: String, now: Instant) {
|
|||||||
.iter()
|
.iter()
|
||||||
.map(|(key, (_, expires_at))| (key.clone(), *expires_at))
|
.map(|(key, (_, expires_at))| (key.clone(), *expires_at))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
entries.sort_by(|left, right| left.1.cmp(&right.1));
|
entries.sort_by_key(|entry| entry.1);
|
||||||
for (key, _) in entries.into_iter().take(cache.len() - CACHE_MAX_ENTRIES) {
|
for (key, _) in entries.into_iter().take(cache.len() - CACHE_MAX_ENTRIES) {
|
||||||
cache.remove(&key);
|
cache.remove(&key);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -514,9 +514,7 @@ impl App {
|
|||||||
KeyCode::Up | KeyCode::Char('k') => {
|
KeyCode::Up | KeyCode::Char('k') => {
|
||||||
self.selected = self.selected.saturating_sub(1);
|
self.selected = self.selected.saturating_sub(1);
|
||||||
}
|
}
|
||||||
KeyCode::Down | KeyCode::Char('j')
|
KeyCode::Down | KeyCode::Char('j') if self.selected + 1 < self.total_field_count() => {
|
||||||
if self.selected + 1 < self.total_field_count() =>
|
|
||||||
{
|
|
||||||
self.selected += 1;
|
self.selected += 1;
|
||||||
}
|
}
|
||||||
KeyCode::Home => self.selected = 0,
|
KeyCode::Home => self.selected = 0,
|
||||||
@@ -624,11 +622,9 @@ impl App {
|
|||||||
let byte = self.char_byte_pos(self.edit_cursor);
|
let byte = self.char_byte_pos(self.edit_cursor);
|
||||||
self.edit_buffer.remove(byte);
|
self.edit_buffer.remove(byte);
|
||||||
}
|
}
|
||||||
KeyCode::Delete => {
|
KeyCode::Delete if self.edit_cursor < self.edit_buffer.chars().count() => {
|
||||||
if self.edit_cursor < self.edit_buffer.chars().count() {
|
let byte = self.char_byte_pos(self.edit_cursor);
|
||||||
let byte = self.char_byte_pos(self.edit_cursor);
|
self.edit_buffer.remove(byte);
|
||||||
self.edit_buffer.remove(byte);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
KeyCode::Left => {
|
KeyCode::Left => {
|
||||||
self.edit_cursor = self.edit_cursor.saturating_sub(1);
|
self.edit_cursor = self.edit_cursor.saturating_sub(1);
|
||||||
|
|||||||
@@ -581,10 +581,8 @@ fn convert_assistant_message(message: &Map<String, Value>) -> Option<Value> {
|
|||||||
let mut text_parts = Vec::new();
|
let mut text_parts = Vec::new();
|
||||||
|
|
||||||
match content {
|
match content {
|
||||||
Some(Value::String(text)) => {
|
Some(Value::String(text)) if !text.is_empty() => {
|
||||||
if !text.is_empty() {
|
text_parts.push(text.clone());
|
||||||
text_parts.push(text.clone());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Some(Value::Array(blocks)) => {
|
Some(Value::Array(blocks)) => {
|
||||||
for block in blocks {
|
for block in blocks {
|
||||||
|
|||||||
@@ -649,18 +649,17 @@ async fn connect_protocol_peer(
|
|||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
match message {
|
match message {
|
||||||
Message::Binary(data) => {
|
Message::Binary(data)
|
||||||
if handle_binary_frame(&mut sink, data.to_vec(), hold)
|
if handle_binary_frame(&mut sink, data.to_vec(), hold)
|
||||||
.await
|
.await
|
||||||
.is_err()
|
.is_err() =>
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Message::Ping(payload) => {
|
Message::Ping(payload)
|
||||||
if sink.send(Message::Pong(payload)).await.is_err() {
|
if sink.send(Message::Pong(payload.clone())).await.is_err() =>
|
||||||
break;
|
{
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
Message::Close(_) => break,
|
Message::Close(_) => break,
|
||||||
_ => {}
|
_ => {}
|
||||||
@@ -691,46 +690,44 @@ where
|
|||||||
let payload = protocol::decode_payload(&data, &header).unwrap_or_default();
|
let payload = protocol::decode_payload(&data, &header).unwrap_or_default();
|
||||||
let _ = serde_json::from_slice::<protocol::RequestMeta>(&payload);
|
let _ = serde_json::from_slice::<protocol::RequestMeta>(&payload);
|
||||||
}
|
}
|
||||||
protocol::REQUEST_BODY => {
|
protocol::REQUEST_BODY if header.flags & protocol::FLAG_END_STREAM != 0 => {
|
||||||
if header.flags & protocol::FLAG_END_STREAM != 0 {
|
tokio::time::sleep(hold).await;
|
||||||
tokio::time::sleep(hold).await;
|
let response_meta = protocol::ResponseMeta {
|
||||||
let response_meta = protocol::ResponseMeta {
|
status: 200,
|
||||||
status: 200,
|
headers: vec![(
|
||||||
headers: vec![(
|
"content-type".to_string(),
|
||||||
"content-type".to_string(),
|
"text/plain; charset=utf-8".to_string(),
|
||||||
"text/plain; charset=utf-8".to_string(),
|
)],
|
||||||
)],
|
};
|
||||||
};
|
let response_meta_json =
|
||||||
let response_meta_json =
|
serde_json::to_vec(&response_meta).expect("response metadata should serialize");
|
||||||
serde_json::to_vec(&response_meta).expect("response metadata should serialize");
|
sink.send(Message::Binary(
|
||||||
sink.send(Message::Binary(
|
protocol::encode_frame(
|
||||||
protocol::encode_frame(
|
header.stream_id,
|
||||||
header.stream_id,
|
protocol::RESPONSE_HEADERS,
|
||||||
protocol::RESPONSE_HEADERS,
|
0,
|
||||||
0,
|
&response_meta_json,
|
||||||
&response_meta_json,
|
)
|
||||||
)
|
.into(),
|
||||||
.into(),
|
))
|
||||||
))
|
.await?;
|
||||||
.await?;
|
|
||||||
|
|
||||||
for chunk in [
|
|
||||||
b"capacity-".as_slice(),
|
|
||||||
b"tunnel-".as_slice(),
|
|
||||||
b"stream".as_slice(),
|
|
||||||
] {
|
|
||||||
sink.send(Message::Binary(
|
|
||||||
protocol::encode_frame(header.stream_id, protocol::RESPONSE_BODY, 0, chunk)
|
|
||||||
.into(),
|
|
||||||
))
|
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
for chunk in [
|
||||||
|
b"capacity-".as_slice(),
|
||||||
|
b"tunnel-".as_slice(),
|
||||||
|
b"stream".as_slice(),
|
||||||
|
] {
|
||||||
sink.send(Message::Binary(
|
sink.send(Message::Binary(
|
||||||
protocol::encode_frame(header.stream_id, protocol::STREAM_END, 0, &[]).into(),
|
protocol::encode_frame(header.stream_id, protocol::RESPONSE_BODY, 0, chunk)
|
||||||
|
.into(),
|
||||||
))
|
))
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sink.send(Message::Binary(
|
||||||
|
protocol::encode_frame(header.stream_id, protocol::STREAM_END, 0, &[]).into(),
|
||||||
|
))
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -140,15 +140,15 @@ async fn connect_protocol_peer(
|
|||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
match message {
|
match message {
|
||||||
Message::Binary(data) => {
|
Message::Binary(data)
|
||||||
if handle_binary_frame(&mut sink, data.to_vec()).await.is_err() {
|
if handle_binary_frame(&mut sink, data.to_vec()).await.is_err() =>
|
||||||
break;
|
{
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
Message::Ping(payload) => {
|
Message::Ping(payload)
|
||||||
if sink.send(Message::Pong(payload)).await.is_err() {
|
if sink.send(Message::Pong(payload.clone())).await.is_err() =>
|
||||||
break;
|
{
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
Message::Close(_) => break,
|
Message::Close(_) => break,
|
||||||
_ => {}
|
_ => {}
|
||||||
@@ -178,45 +178,43 @@ where
|
|||||||
let payload = protocol::decode_payload(&data, &header).unwrap_or_default();
|
let payload = protocol::decode_payload(&data, &header).unwrap_or_default();
|
||||||
let _ = serde_json::from_slice::<protocol::RequestMeta>(&payload);
|
let _ = serde_json::from_slice::<protocol::RequestMeta>(&payload);
|
||||||
}
|
}
|
||||||
protocol::REQUEST_BODY => {
|
protocol::REQUEST_BODY if header.flags & protocol::FLAG_END_STREAM != 0 => {
|
||||||
if header.flags & protocol::FLAG_END_STREAM != 0 {
|
let response_meta = protocol::ResponseMeta {
|
||||||
let response_meta = protocol::ResponseMeta {
|
status: 200,
|
||||||
status: 200,
|
headers: vec![(
|
||||||
headers: vec![(
|
"content-type".to_string(),
|
||||||
"content-type".to_string(),
|
"text/plain; charset=utf-8".to_string(),
|
||||||
"text/plain; charset=utf-8".to_string(),
|
)],
|
||||||
)],
|
};
|
||||||
};
|
let response_meta_json =
|
||||||
let response_meta_json =
|
serde_json::to_vec(&response_meta).expect("response metadata should serialize");
|
||||||
serde_json::to_vec(&response_meta).expect("response metadata should serialize");
|
sink.send(Message::Binary(
|
||||||
sink.send(Message::Binary(
|
protocol::encode_frame(
|
||||||
protocol::encode_frame(
|
header.stream_id,
|
||||||
header.stream_id,
|
protocol::RESPONSE_HEADERS,
|
||||||
protocol::RESPONSE_HEADERS,
|
0,
|
||||||
0,
|
&response_meta_json,
|
||||||
&response_meta_json,
|
)
|
||||||
)
|
.into(),
|
||||||
.into(),
|
))
|
||||||
))
|
.await?;
|
||||||
.await?;
|
|
||||||
|
|
||||||
for chunk in [
|
|
||||||
b"baseline-".as_slice(),
|
|
||||||
b"tunnel-".as_slice(),
|
|
||||||
b"stream".as_slice(),
|
|
||||||
] {
|
|
||||||
sink.send(Message::Binary(
|
|
||||||
protocol::encode_frame(header.stream_id, protocol::RESPONSE_BODY, 0, chunk)
|
|
||||||
.into(),
|
|
||||||
))
|
|
||||||
.await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
for chunk in [
|
||||||
|
b"baseline-".as_slice(),
|
||||||
|
b"tunnel-".as_slice(),
|
||||||
|
b"stream".as_slice(),
|
||||||
|
] {
|
||||||
sink.send(Message::Binary(
|
sink.send(Message::Binary(
|
||||||
protocol::encode_frame(header.stream_id, protocol::STREAM_END, 0, &[]).into(),
|
protocol::encode_frame(header.stream_id, protocol::RESPONSE_BODY, 0, chunk)
|
||||||
|
.into(),
|
||||||
))
|
))
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sink.send(Message::Binary(
|
||||||
|
protocol::encode_frame(header.stream_id, protocol::STREAM_END, 0, &[]).into(),
|
||||||
|
))
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -381,18 +381,17 @@ async fn connect_protocol_peer(
|
|||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
match message {
|
match message {
|
||||||
Message::Binary(data) => {
|
Message::Binary(data)
|
||||||
if handle_binary_frame(&mut sink, data.to_vec(), chunk_delay)
|
if handle_binary_frame(&mut sink, data.to_vec(), chunk_delay)
|
||||||
.await
|
.await
|
||||||
.is_err()
|
.is_err() =>
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Message::Ping(payload) => {
|
Message::Ping(payload)
|
||||||
if sink.send(Message::Pong(payload)).await.is_err() {
|
if sink.send(Message::Pong(payload.clone())).await.is_err() =>
|
||||||
break;
|
{
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
Message::Close(_) => break,
|
Message::Close(_) => break,
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|||||||
Reference in New Issue
Block a user