Move api_root to global scope

This commit is contained in:
Igor Katson 2025-01-14 10:05:23 +00:00
parent d3323ac7ac
commit c474d7b454
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5

View file

@ -592,25 +592,7 @@ async fn update_session_ratelimits(
Ok(Json(EmptyJsonResponse {})) Ok(Json(EmptyJsonResponse {}))
} }
impl HttpApi { async fn api_root(parts: Parts) -> impl IntoResponse {
pub fn new(api: Api, opts: Option<HttpApiOptions>) -> Self {
Self {
api,
opts: opts.unwrap_or_default(),
}
}
/// Run the HTTP server forever on the given address.
/// If read_only is passed, no state-modifying methods will be exposed.
#[inline(never)]
pub fn make_http_api_and_run(
self,
listener: TcpListener,
upnp_router: Option<Router>,
) -> BoxFuture<'static, anyhow::Result<()>> {
let state = Arc::new(self);
let api_root = move |parts: Parts| async move {
// If browser, and webui enabled, redirect to web // If browser, and webui enabled, redirect to web
#[cfg(feature = "webui")] #[cfg(feature = "webui")]
{ {
@ -651,7 +633,25 @@ impl HttpApi {
"version": env!("CARGO_PKG_VERSION"), "version": env!("CARGO_PKG_VERSION"),
})), })),
).into_response() ).into_response()
}; }
impl HttpApi {
pub fn new(api: Api, opts: Option<HttpApiOptions>) -> Self {
Self {
api,
opts: opts.unwrap_or_default(),
}
}
/// Run the HTTP server forever on the given address.
/// If read_only is passed, no state-modifying methods will be exposed.
#[inline(never)]
pub fn make_http_api_and_run(
self,
listener: TcpListener,
upnp_router: Option<Router>,
) -> BoxFuture<'static, anyhow::Result<()>> {
let state = Arc::new(self);
let mut app = Router::new() let mut app = Router::new()
.route("/", get(api_root)) .route("/", get(api_root))