use serde::{Deserialize}; #[derive(Clone, Debug, Deserialize, Default)] pub struct Module { pub name: String, pub title: String, pub key: String, pub dflt_lang: String, #[serde(default = "default_empty")] pub template_path: String, pub logo_url: String, pub css_url: String, pub bg_url: String, pub color: String, pub main_color: String, pub main_bg: String, pub css_color: String, #[serde(default = "default_empty")] pub captcha_color: String, #[serde(default = "default_empty")] pub manifesto: String, pub stores: String, #[serde(default = "default_bool")] pub init_load: bool, #[serde(default = "default_empty")] pub store_root: String, #[serde(default = "default_empty")] pub store_path: String, #[serde(default = "default_empty")] pub store_frmt: String, #[serde(default = "default_empty")] pub upload_path: String, } fn default_empty() -> String { "".to_string() } fn default_bool() -> bool { false } impl Module { pub fn load_fs_content(path: &std::path::PathBuf) -> String { std::fs::read_to_string(path) .unwrap_or_else(|e| { eprintln!("{}",e); String::from("") }) } pub fn new(content: String) -> Self { // let modul_def: toml::Value = toml::from_str(&content)?; // if let Some(name) = modul_def["name"].as_str() { match toml::from_str(&content) { Ok(cfg) => { println!("Module Loaded successfully"); let app_home=envmnt::get_or("APP_HOME", ""); if app_home.is_empty() { cfg } else { let mut module_cfg = cfg; module_cfg.store_root=format!("{}{}",&app_home,&module_cfg.store_root); module_cfg } }, Err(e) => { println!("Module error: {}",e); Module::default() } } } }