feat: stream from original backend

chore: 🙈 audios
This commit is contained in:
Ahmet Kaan GÜMÜŞ 2024-03-18 04:08:14 +03:00
parent 1992354aed
commit 5aafa9befd
4 changed files with 14 additions and 2 deletions

View file

@ -12,4 +12,6 @@ rand = "0.8.5"
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.114"
tokio = { version = "1.36.0", features = ["full"] }
#tokio-stream = { version = "0.1.15", features = ["full"] }
tokio-util = { version = "0.7.10", features = ["full"] }
tower-http = { version = "0.5.2", features = ["full"] }

View file

@ -1,5 +1,7 @@
use crate::{AppState, ServerStatus, CoinStatus};
use axum::{extract::State, http::StatusCode, response::IntoResponse, routing::get, Json, Router};
use axum::{body::Body, extract::State, http::StatusCode, response::IntoResponse, routing::get, Json, Router};
use tokio::fs::File;
use tokio_util::io::ReaderStream;
use tower_http::cors::CorsLayer;
use rand::prelude::*;
@ -7,6 +9,7 @@ pub async fn routing(State(state): State<AppState>) -> Router {
Router::new()
.route("/", get(alive))
.route("/coin", get(flip_coin))
.route("/stream", get(stream))
.layer(CorsLayer::permissive())
.with_state(state.clone())
}
@ -32,3 +35,9 @@ async fn flip_coin() -> impl IntoResponse {
println!("{}", coin_json);
(StatusCode::OK, Json(coin_json))
}
async fn stream() -> impl IntoResponse {
let file = File::open("audios/audio.mp3").await.unwrap();
let stream = ReaderStream::new(file);
Body::from_stream(stream)
}