use std::path::PathBuf; #[derive(Clone)] pub struct StaticFilesManager { index: Vec<String>, } impl StaticFilesManager { fn create_dir_if_missing(app_dir: &PathBuf) -> Result<(), String> { let static_path = app_dir.join("static"); if !static_path.exists() { match std::fs::create_dir_all(static_path) { Ok(_) => return Self::copy_default(&app_dir), Err(err) => return Err(format!("{}", err)), } } Ok(()) } fn copy_default(app_dir: &PathBuf) -> Result<(), String> { let local_default = std::env::current_dir().unwrap().join("default_static"); let standard_default = app_dir.join("static").join("default"); if let Err(err) = std::fs::create_dir_all(&standard_default) { return Err(format!("{}", err)); } let mut copy_default_options = fs_extra::dir::CopyOptions::new(); copy_default_options.content_only = true; if let Err(err) = fs_extra::dir::copy(local_default, standard_default, ©_default_options) { return Err(format!("{}", err)); }; Ok(()) } pub fn new(website_name: &String) -> Result<Self, String> { if let Err(err) = Self::create_dir_if_missing(&dirs::home_dir().unwrap().join(website_name)) { return Err(err); } Ok(StaticFilesManager { index: Vec::new() }) } pub fn build_index(&mut self) -> Result<(), String> { self.index.push("TODO".to_string()); Ok(()) } }