From e8207e45e09761570990812bddf4ccd7fbb3b364 Mon Sep 17 00:00:00 2001 From: Dan Nixon Date: Sun, 21 Jan 2024 18:37:32 +0000 Subject: [PATCH] wip --- agent/src/main.rs | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/agent/src/main.rs b/agent/src/main.rs index 589dba8..2c0f3dc 100644 --- a/agent/src/main.rs +++ b/agent/src/main.rs @@ -3,6 +3,7 @@ mod ffmpeg; mod utils; use axum::{ + http::header, response::{Html, IntoResponse}, routing::get, Router, @@ -87,21 +88,27 @@ async fn main() { .await .unwrap_or_else(|_| panic!("tcp listener should bind to {}", cli.http_server_address)); - // Configure HTTP server routes let frame_image = SharedImageData::default(); - let frame_image_2 = frame_image.clone(); - let app = Router::new() - .route("/player", get(Html(include_str!("player.html")))) - .route( - "/frame.jpg", - get(move || async move { - match frame_image_2.lock().unwrap().as_ref() { - Some(image) => image.clone().into_response(), - None => axum::http::StatusCode::NOT_FOUND.into_response(), - } - }), - ) - .nest_service("/", ServeDir::new(config.video_directory.clone())); + + // Configure HTTP server routes + let app = { + let frame_image = frame_image.clone(); + + Router::new() + .route("/player", get(Html(include_str!("player.html")))) + .route( + "/frame.jpg", + get(move || async move { + match frame_image.lock().unwrap().as_ref() { + Some(image) => { + ([(header::CONTENT_TYPE, "image/jpeg")], image.clone()).into_response() + } + None => axum::http::StatusCode::NOT_FOUND.into_response(), + } + }), + ) + .nest_service("/", ServeDir::new(config.video_directory.clone())) + }; // Start HTTP server info!("Starting HTTP server on {}", cli.http_server_address);