2026-03-17 13:49:03 +00:00
|
|
|
pub mod auth;
|
|
|
|
|
pub mod browse;
|
|
|
|
|
pub mod meta;
|
|
|
|
|
pub mod stream;
|
|
|
|
|
pub mod transcoder;
|
|
|
|
|
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
|
|
use axum::{
|
|
|
|
|
Router,
|
|
|
|
|
middleware,
|
|
|
|
|
routing::get,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// Shared state passed to all web handlers.
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
pub struct WebState {
|
|
|
|
|
pub root: Arc<PathBuf>,
|
|
|
|
|
pub token: Arc<String>,
|
2026-03-17 14:23:49 +00:00
|
|
|
pub oidc: Option<Arc<OidcState>>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct OidcState {
|
|
|
|
|
pub client: openidconnect::core::CoreClient,
|
|
|
|
|
pub session_secret: Vec<u8>,
|
2026-03-17 13:49:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Build the axum Router for the web player.
|
2026-03-17 14:23:49 +00:00
|
|
|
pub fn build_router(root: PathBuf, token: String, oidc: Option<Arc<OidcState>>) -> Router {
|
2026-03-17 13:49:03 +00:00
|
|
|
let state = WebState {
|
|
|
|
|
root: Arc::new(root),
|
|
|
|
|
token: Arc::new(token),
|
2026-03-17 14:23:49 +00:00
|
|
|
oidc,
|
2026-03-17 13:49:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let api = Router::new()
|
|
|
|
|
.route("/browse", get(browse::handler))
|
|
|
|
|
.route("/stream/*path", get(stream::handler))
|
|
|
|
|
.route("/meta/*path", get(meta::handler));
|
|
|
|
|
|
|
|
|
|
let authed_routes = Router::new()
|
|
|
|
|
.route("/", get(player_html))
|
|
|
|
|
.nest("/api", api)
|
|
|
|
|
.route_layer(middleware::from_fn_with_state(state.clone(), auth::require_auth));
|
|
|
|
|
|
|
|
|
|
Router::new()
|
|
|
|
|
.route("/login", get(auth::login_page).post(auth::login_submit))
|
|
|
|
|
.route("/logout", get(auth::logout))
|
2026-03-17 14:23:49 +00:00
|
|
|
.route("/auth/login", get(auth::oidc_login))
|
|
|
|
|
.route("/auth/callback", get(auth::oidc_callback))
|
2026-03-17 13:49:03 +00:00
|
|
|
.merge(authed_routes)
|
|
|
|
|
.with_state(state)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn player_html() -> axum::response::Html<&'static str> {
|
|
|
|
|
axum::response::Html(include_str!("player.html"))
|
|
|
|
|
}
|