Changed file serving to use asset directory from config

This commit is contained in:
2025-10-06 22:33:32 +02:00
parent 2500fdc79b
commit f01659ea50

View File

@@ -1,13 +1,13 @@
use crate::AppState;
use actix_web::web::Path; use actix_web::web::Path;
use actix_web::{HttpResponse, Responder, get}; use actix_web::{HttpResponse, Responder, get, web};
use std::fs::File; use std::fs::File;
use std::io::Read; use std::io::Read;
use std::path::PathBuf; use std::path::PathBuf;
#[get("/static/{file_type}/{file_name}")] #[get("/static/{file_type}/{file_name}")]
async fn file(file: Path<(String, String)>) -> impl Responder { async fn file(file: Path<(String, String)>, data: web::Data<AppState>) -> impl Responder {
//TODO use assets dir let mut path = PathBuf::from(&data.assets);
let mut path = PathBuf::from("assets");
path.push(&file.0.replace("/", "")); path.push(&file.0.replace("/", ""));
path.push(&file.1.replace("/", "")); path.push(&file.1.replace("/", ""));
let mut file = File::open(path).unwrap(); let mut file = File::open(path).unwrap();