heldar_kernel/routes/
liveview.rs1use axum::extract::{Path, State};
2use axum::routing::get;
3use axum::{Json, Router};
4
5use crate::auth::Principal;
6use crate::error::AppResult;
7use crate::services::mediamtx::{self, LiveUrls};
8use crate::state::AppState;
9
10pub fn router() -> Router<AppState> {
11 Router::new().route(
12 "/api/v1/cameras/{id}/liveview",
13 get(liveview).post(liveview),
14 )
15}
16
17async fn liveview(
19 State(st): State<AppState>,
20 principal: Principal,
21 Path(id): Path<String>,
22) -> AppResult<Json<LiveUrls>> {
23 principal.require(principal.can_view(), "view live streams")?;
25 Ok(Json(mediamtx::ensure_live(&st, &id).await?))
26}