use std::fs::File; use std::io::{BufReader, Read}; use std::path::PathBuf; use actix_web::{get, HttpResponse}; use actix_web::web::{Data, Path}; use handlebars::Handlebars; use log::info; use serde_json::json; use crate::Result; #[get("/+{id}")] pub async fn get(id: Path, hb: Data>) -> Result { let mut path = PathBuf::from("replays"); let id: String = id.into_inner(); path.push(&id); let file: File = File::open(&path)?; let mut buffer = BufReader::new(file); let mut file_contents = String::new(); buffer.read_to_string(&mut file_contents)?; info!("read to buffer"); let data = json!({ "replayid": id, }); let body = hb.render("replay", &data).unwrap(); Ok(HttpResponse::Ok().body(body)) }