diff --git a/backend/src/main.rs b/backend/src/main.rs index 5ca92deb4..4a9ff4107 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -1,8 +1,10 @@ use std::time::Duration; use axum::{ + body::Body, extract::{Path, State}, http::{HeaderValue, Method, StatusCode}, + response::Response, routing::{get, post}, Json, Router, }; @@ -56,6 +58,7 @@ async fn main() { ]); let app = Router::new() + .route("/active", get(active_boards)) .route("/subscribe/:bid", get(subscribe)) .route("/refresh/:bid", post(trigger)) .route("/update", post(update)) @@ -68,6 +71,20 @@ async fn main() { .unwrap() } +async fn active_boards( + AuthBearer(token): AuthBearer, + State(mut state): State, +) -> Result, AppError> { + if token != state.key { + return Ok(Response::builder() + .status(StatusCode::UNAUTHORIZED) + .body(Body::from(0.to_string())) + .unwrap()); + } + let active_boards = state.master.get::<&str, i32>("active_boards").await?; + Ok(Response::new(Body::from(active_boards.to_string()))) +} + async fn trigger( Path(bid): Path, AuthBearer(token): AuthBearer,