Added main page and static files

This commit is contained in:
2025-10-05 23:29:11 +02:00
parent af6fb8fd68
commit 4b10832591
2 changed files with 64 additions and 0 deletions

19
src/pages/files.rs Normal file
View File

@@ -0,0 +1,19 @@
use actix_web::web::Path;
use actix_web::{HttpResponse, Responder, get};
use std::fs::File;
use std::io::Read;
use std::path::PathBuf;
#[get("/static/{file_type}/{file_name}")]
async fn file(file: Path<(String, String)>) -> impl Responder {
//TODO use assets dir
let mut path = PathBuf::from("assets");
path.push(&file.0.replace("/", ""));
path.push(&file.1.replace("/", ""));
let mut file = File::open(path).unwrap();
let mut bytes = Vec::new();
if file.read_to_end(&mut bytes).is_err() {
return HttpResponse::NotFound().body("File not found");
};
HttpResponse::Ok().body(bytes)
}