From 332f5d54ee5dd6ec4c56996b98021195d46bdd26 Mon Sep 17 00:00:00 2001 From: Dan Nixon Date: Sun, 21 Jan 2024 18:23:06 +0000 Subject: [PATCH] wip --- agent/src/main.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/agent/src/main.rs b/agent/src/main.rs index e5dd79f..589dba8 100644 --- a/agent/src/main.rs +++ b/agent/src/main.rs @@ -2,7 +2,11 @@ mod config; mod ffmpeg; mod utils; -use axum::{response::Html, routing::get, Router}; +use axum::{ + response::{Html, IntoResponse}, + routing::get, + Router, +}; use clap::Parser; use metrics_exporter_prometheus::PrometheusBuilder; use std::{fs, net::SocketAddr, path::PathBuf, time::Duration}; @@ -85,9 +89,18 @@ async fn main() { // 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")))) - // .nest_service("/frame.jpg", ServeFile::new(frame_file)) + .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())); // Start HTTP server