chore: update dependencies and improve chart components

- Updated `foreign-types` to version 0.5.0 and added new dependencies in `Cargo.lock`.
- Removed unused dependencies `chart.js` and `react-chartjs-2` from `package.json` and `package-lock.json`.
- Enhanced `CacheHitRateChart` to use `EChart` for rendering, improving performance and visual fidelity.
- Adjusted styles for `CacheHitRateChart` to ensure proper layout and responsiveness.
- Refactored API query construction in `api.ts` for better readability.
- Updated `HomeMetrics` to support refresh functionality for dynamic data updates.
This commit is contained in:
leookun committed 2026-08-27 00:34:35 +08:00
1 parent 7058d0193d
commit 995a12df44
20 files changed
+560 -154

No files matched your search

+24 -3
View File
@@ -2,6 +2,8 @@ use std::{cmp::Ordering, collections::HashMap};
use futures_util::future::join_all;
use crate::store::Store;
use super::{catalog, SearchEngine, SearchHit};
const RRF_K: f64 = 60.0;
@@ -9,10 +11,16 @@ const MAX_RESULTS: usize = 10;
#[derive(Clone)]
pub struct WebSearch {
client: reqwest::Client,
client: SearchClient,
engines: Vec<SearchEngine>,
}
#[derive(Clone)]
enum SearchClient {
Managed(Store),
Direct(reqwest::Client),
}
#[derive(Debug, thiserror::Error)]
#[error("web search failed: {0}")]
pub struct SearchError(String);
@@ -22,13 +30,20 @@ impl WebSearch {
Self::with_engines(catalog::engines())
}
pub(crate) fn managed(store: Store) -> Self {
Self {
client: SearchClient::Managed(store),
engines: catalog::engines(),
}
}
pub fn with_engines<I, E>(engines: I) -> Self
where
I: IntoIterator<Item = E>,
E: Into<SearchEngine>,
{
Self {
client: reqwest::Client::new(),
client: SearchClient::Direct(reqwest::Client::new()),
engines: engines.into_iter().map(Into::into).collect(),
}
}
@@ -42,10 +57,16 @@ impl WebSearch {
if query.is_empty() {
return Err(SearchError("query is empty".into()));
}
let client = match &self.client {
SearchClient::Managed(store) => crate::network::client(store)
.await
.map_err(|error| SearchError(format!("HTTP client failed: {error}")))?,
SearchClient::Direct(client) => client.clone(),
};
let responses = join_all(
self.engines
.iter()
.map(|engine| engine.search(&self.client, query)),
.map(|engine| engine.search(&client, query)),
)
.await;
let mut merged = HashMap::<String, SearchHit>::new();
+25 -1
View File
@@ -14,6 +14,8 @@ use reqwest::{
use tokio::{net::lookup_host, time::timeout};
use url::{Host, Url};
use crate::store::Store;
const MAX_RESPONSE_SIZE: usize = 5 * 1024 * 1024;
const MAX_REDIRECTS: usize = 5;
const FETCH_TIMEOUT: Duration = Duration::from_secs(30);
@@ -38,12 +40,27 @@ enum NetworkPolicy {
#[derive(Clone)]
pub struct WebFetch {
network: NetworkPolicy,
client: FetchClient,
}
#[derive(Clone)]
enum FetchClient {
Managed(Store),
Direct,
}
impl WebFetch {
pub fn built_in() -> Self {
Self {
network: NetworkPolicy::PublicOnly,
client: FetchClient::Direct,
}
}
pub(crate) fn managed(store: Store) -> Self {
Self {
network: NetworkPolicy::PublicOnly,
client: FetchClient::Managed(store),
}
}
@@ -51,6 +68,7 @@ impl WebFetch {
pub(crate) fn for_test() -> Self {
Self {
network: NetworkPolicy::Any,
client: FetchClient::Direct,
}
}
@@ -111,7 +129,13 @@ impl WebFetch {
return Err(failure("URL resolves to a non-public address"));
}
let mut builder = reqwest::Client::builder()
let builder = match &self.client {
FetchClient::Managed(store) => crate::network::client_builder(store)
.await
.map_err(|error| failure(format!("HTTP client failed: {error}")))?,
FetchClient::Direct => reqwest::Client::builder().use_native_tls(),
};
let mut builder = builder
.redirect(Policy::none())
.connect_timeout(Duration::from_secs(10));
if domain {