feat: Added http server that serve the same files

This commit is contained in:
2026-10-20 02:56:39 +02:00
parent a5594c768d
commit 620f36d0bb
7 changed files with 210 additions and 38 deletions
+31
View File
@@ -0,0 +1,31 @@
use std::path::PathBuf;
use axum::debug_handler;
use axum::extract::Request;
use axum::response::IntoResponse;
use reqwest::{StatusCode, header};
use crate::file::get_file;
#[debug_handler]
pub async fn handler(req: Request) -> impl IntoResponse {
let Some(path) = req.uri().path().strip_prefix("/") else {
return StatusCode::BAD_REQUEST.into_response();
};
let Some((file, content_type)) = get_file(path).await else {
return StatusCode::NOT_FOUND.into_response();
};
let path = PathBuf::from(path);
let filename = path.file_name().unwrap();
let filename = filename.to_str().unwrap();
let content_type = [(header::CONTENT_TYPE, content_type)];
let disposition = [(
header::CONTENT_DISPOSITION,
format!("inline; filename=\"{filename}\""),
)];
(content_type, disposition, file).into_response()
}