initial prototype
This commit is contained in:
34
src/main.rs
Normal file
34
src/main.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
mod downloader;
|
||||
mod state;
|
||||
mod streamer;
|
||||
|
||||
use axum::{extract::State, routing::get, Router};
|
||||
use state::AppState;
|
||||
use std::sync::Arc;
|
||||
|
||||
async fn new(State(state): State<Arc<AppState>>) -> &'static str {
|
||||
let Ok(url) = player::newest_morning_journal_streaming_url().await else {
|
||||
return "Failed getting latest url";
|
||||
};
|
||||
|
||||
downloader::spawn_download_task(&url, state.clone());
|
||||
|
||||
"Download started. Access / to stream the new content."
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let state = Arc::new(AppState::new());
|
||||
|
||||
let app = Router::new()
|
||||
.route("/", get(streamer::stream_handler))
|
||||
.route("/new", get(new))
|
||||
.with_state(state);
|
||||
|
||||
println!("Streaming server running on http://localhost:3000");
|
||||
|
||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;
|
||||
axum::serve(listener, app).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
Reference in New Issue
Block a user