LazyLock
This commit is contained in:
parent
c474d7b454
commit
8b35ddd59c
1 changed files with 17 additions and 9 deletions
|
|
@ -18,7 +18,7 @@ use serde::{Deserialize, Serialize};
|
||||||
use std::io::SeekFrom;
|
use std::io::SeekFrom;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
use std::sync::{Arc, LazyLock};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::io::AsyncSeekExt;
|
use tokio::io::AsyncSeekExt;
|
||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
|
|
@ -596,16 +596,18 @@ async fn api_root(parts: Parts) -> impl IntoResponse {
|
||||||
// If browser, and webui enabled, redirect to web
|
// If browser, and webui enabled, redirect to web
|
||||||
#[cfg(feature = "webui")]
|
#[cfg(feature = "webui")]
|
||||||
{
|
{
|
||||||
if parts.headers.get("Accept").map_or(false, |h| {
|
if parts
|
||||||
std::str::from_utf8(h.as_bytes()).map_or(false, |s| s.contains("text/html"))
|
.headers
|
||||||
}) {
|
.get("Accept")
|
||||||
|
.and_then(|h| h.to_str().ok())
|
||||||
|
.map_or(false, |h| h.contains("text/html"))
|
||||||
|
{
|
||||||
return Redirect::temporary("./web/").into_response();
|
return Redirect::temporary("./web/").into_response();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(
|
static API_ROOT_JSON: LazyLock<Arc<serde_json::Value>> = LazyLock::new(|| {
|
||||||
[("Content-Type", "application/json")],
|
Arc::new(serde_json::json!({
|
||||||
axum::Json(serde_json::json!({
|
|
||||||
"apis": {
|
"apis": {
|
||||||
"GET /": "list all available APIs",
|
"GET /": "list all available APIs",
|
||||||
"GET /dht/stats": "DHT stats",
|
"GET /dht/stats": "DHT stats",
|
||||||
|
|
@ -631,8 +633,14 @@ async fn api_root(parts: Parts) -> impl IntoResponse {
|
||||||
},
|
},
|
||||||
"server": "rqbit",
|
"server": "rqbit",
|
||||||
"version": env!("CARGO_PKG_VERSION"),
|
"version": env!("CARGO_PKG_VERSION"),
|
||||||
})),
|
}))
|
||||||
).into_response()
|
});
|
||||||
|
|
||||||
|
(
|
||||||
|
[("Content-Type", "application/json")],
|
||||||
|
axum::Json(API_ROOT_JSON.clone()),
|
||||||
|
)
|
||||||
|
.into_response()
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HttpApi {
|
impl HttpApi {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue