Added web player

This commit is contained in:
Ultradesu
2026-03-17 13:49:03 +00:00
parent f2d42751fd
commit 46ba3d5490
10 changed files with 2298 additions and 15 deletions

View File

@@ -2,6 +2,7 @@ pub mod vfs;
pub mod security;
pub mod server;
pub mod metrics;
pub mod web;
use std::net::SocketAddr;
use std::path::PathBuf;
@@ -33,6 +34,14 @@ struct Args {
#[arg(long, env = "FURUMI_METRICS_BIND", default_value = "0.0.0.0:9090")]
metrics_bind: String,
/// IP address and port for the web music player
#[arg(long, env = "FURUMI_WEB_BIND", default_value = "0.0.0.0:8080")]
web_bind: String,
/// Disable the web music player UI
#[arg(long, default_value_t = false)]
no_web: bool,
/// Disable TLS encryption (not recommended, use only for debugging)
#[arg(long, default_value_t = false)]
no_tls: bool,
@@ -91,7 +100,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Authentication: enabled (Bearer token)");
}
println!("Document Root: {:?}", root_path);
println!("Metrics: http://{}/metrics", metrics_addr);
println!("Metrics: http://{}/metrics", metrics_addr);
// Spawn the Prometheus metrics HTTP server on a separate port
let metrics_app = Router::new().route("/metrics", get(metrics_handler));
@@ -100,6 +109,20 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
axum::serve(metrics_listener, metrics_app).await.unwrap();
});
// Spawn the web music player on its own port
if !args.no_web {
let web_addr: SocketAddr = args.web_bind.parse().unwrap_or_else(|e| {
eprintln!("Error: Invalid web bind address '{}': {}", args.web_bind, e);
std::process::exit(1);
});
let web_app = web::build_router(root_path.clone(), args.token.clone());
let web_listener = tokio::net::TcpListener::bind(web_addr).await?;
println!("Web player: http://{}", web_addr);
tokio::spawn(async move {
axum::serve(web_listener, web_app).await.unwrap();
});
}
let mut builder = Server::builder()
.tcp_keepalive(Some(std::time::Duration::from_secs(60)))
.http2_keepalive_interval(Some(std::time::Duration::from_secs(60)));