use axum::body::Body;
use axum::extract::{Path, State};
use axum::http::header::CONTENT_TYPE;
use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use uuid::Uuid;
use crate::AppState;
pub async fn serve_expose(State(state): State<AppState>, Path(id): Path<String>) -> Response {
let Ok(id) = Uuid::parse_str(&id) else {
return StatusCode::NOT_FOUND.into_response();
};
let Some(path) = state.app.expose.get(id) else {
return StatusCode::NOT_FOUND.into_response();
};
match tokio::fs::read(&path).await {
Ok(bytes) => (
[(CONTENT_TYPE, "application/octet-stream")],
Body::from(bytes),
)
.into_response(),
Err(_) => StatusCode::NOT_FOUND.into_response(),
}
}