diff --git a/README.md b/README.md index a6f9e6d..eda7506 100644 --- a/README.md +++ b/README.md @@ -134,7 +134,7 @@ Compatible with all librespeed clients : ipinfo_api_key="" # set directory of speedtest web front to server load on `/`. If it is empty, default web will be returned - speed_test_dir="./assets" # Write without suffix separator + assets_path="./assets" # Write without suffix separator # password for logging into statistics page, fill this to enable stats page stats_password="" diff --git a/configs.toml b/configs.toml index 88ebee4..24f90ad 100644 --- a/configs.toml +++ b/configs.toml @@ -15,7 +15,7 @@ base_url="backend" ipinfo_api_key="" # set directory of speedtest web front to server load on `/`. If it is empty, default web will be returned -speed_test_dir="./assets" # Write without suffix separator +assets_path="./assets" # Write without suffix separator # password for logging into statistics page, fill this to enable stats page stats_password="" @@ -34,4 +34,4 @@ database_file="speedtest.db" # enable and use TLS option; if enable it, you need to prepare certificates and private keys enable_tls=false tls_cert_file="" -tls_key_file="" \ No newline at end of file +tls_key_file="" diff --git a/src/cmd.rs b/src/cmd.rs index d5e512c..c283081 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -8,7 +8,7 @@ pub struct Cmd { pub listen_port : Option, pub base_url : Option, pub ipinfo_api_key : Option, - pub speed_test_dir : Option, + pub assets_path : Option, pub stats_password : Option, pub database_type : Option, pub database_hostname : Option, @@ -71,8 +71,8 @@ impl Cmd { .value_parser(value_parser!(String)) ) .arg( - Arg::new("speed-test-dir") - .long("speed-test-dir") + Arg::new("assets-path") + .long("assets-path") .help("Specify the directory of speedtest web frontend") .value_parser(value_parser!(String)) ) @@ -143,7 +143,7 @@ impl Cmd { let listen_port : Option = args.get_one::("listen-port").map(|s| s.to_owned()); let base_url : Option = args.get_one::("base-url").map(|s| s.to_owned()); let ipinfo_api_key : Option = args.get_one::("ipinfo-api-key").map(|s| s.to_owned()); - let speed_test_dir : Option = args.get_one::("speed-test-dir").map(|s| s.to_owned()); + let assets_path : Option = args.get_one::("assets-path").map(|s| s.to_owned()); let stats_password : Option = args.get_one::("stats-password").map(|s| s.to_owned()); let database_type : Option = args.get_one::("database-type").map(|s| s.to_owned()); let database_hostname : Option = args.get_one::("database-hostname").map(|s| s.to_owned()); @@ -161,7 +161,7 @@ impl Cmd { listen_port, base_url, ipinfo_api_key, - speed_test_dir, + assets_path, stats_password, database_type, database_hostname, @@ -175,4 +175,4 @@ impl Cmd { } } -} \ No newline at end of file +} diff --git a/src/config/mod.rs b/src/config/mod.rs index de91e2c..5db24e5 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -43,7 +43,7 @@ pub struct ServerConfig { pub base_url : String, pub ipinfo_api_key : String, pub stats_password : String, - pub speed_test_dir : String, + pub assets_path : String, pub database_type : String, pub database_hostname : Option, pub database_name : Option, @@ -64,7 +64,7 @@ impl Default for ServerConfig { base_url: "backend".to_string(), ipinfo_api_key: "".to_string(), stats_password: "".to_string(), - speed_test_dir: "".to_string(), + assets_path: "".to_string(), database_type: "none".to_string(), database_hostname: None, database_name: None, @@ -189,7 +189,7 @@ fn initialize (mut config: ServerConfig,cmd : Cmd) -> std::io::Result<()> { config.listen_port.set_if_some(cmd.listen_port); config.base_url.set_if_some(cmd.base_url); config.ipinfo_api_key.set_if_some(cmd.ipinfo_api_key); - config.speed_test_dir.set_if_some(cmd.speed_test_dir); + config.assets_path.set_if_some(cmd.assets_path); config.stats_password.set_if_some(cmd.stats_password); config.database_type.set_if_some(cmd.database_type); config.database_hostname.set_if_some(cmd.database_hostname); @@ -201,14 +201,14 @@ fn initialize (mut config: ServerConfig,cmd : Cmd) -> std::io::Result<()> { config.tls_cert_file.set_if_some(cmd.tls_cert_file); config.tls_key_file.set_if_some(cmd.tls_key_file); generate_routes(&config.base_url); - if !config.speed_test_dir.is_empty() { - if check_speed_test_dir(&config.speed_test_dir) { - info!("Config speed test directory successfully.") + if !config.assets_path.is_empty() { + if check_assets_path(&config.assets_path) { + info!("Config assets directory successfully.") } else { - info!("Config speed test directory failed !") + info!("Config assets directory failed !") } } else { - info!("Config default speed test directory.") + info!("Config default assets directory.") } SERVER_CONFIG.get_or_init(|| config); //garbage data @@ -223,7 +223,7 @@ fn initialize (mut config: ServerConfig,cmd : Cmd) -> std::io::Result<()> { Ok(()) } -fn check_speed_test_dir (dir : &str) -> bool { +fn check_assets_path (dir : &str) -> bool { let index_file = format!("{}/index.html",dir); Path::new(&index_file).exists() } @@ -242,4 +242,4 @@ pub const HEAD_ART : &str = r#" | | | |_) | | | __/\__ \ |_) | __/ __/ (_| |_____| | \__ \ |_|_|_.__/|_| \___||___/ .__/ \___|\___|\__,_| |_| |___/ |_| -"#; \ No newline at end of file +"#; diff --git a/src/http/mod.rs b/src/http/mod.rs index 2d7761c..9075124 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -39,7 +39,7 @@ pub async fn find_remote_ip_addr (conn: &mut TcpStream) -> String { } pub fn get_index_file_content(file_name : &str) -> Option> { - if SERVER_CONFIG.get()?.speed_test_dir.is_empty() { + if SERVER_CONFIG.get()?.assets_path.is_empty() { if file_name.contains("servers_list.js") { Some(generate_server_endpoint()) } else { @@ -48,7 +48,7 @@ pub fn get_index_file_content(file_name : &str) -> Option> { Some(Vec::from(file.contents())) } } else { - let file_path = format!("{}{}",SERVER_CONFIG.get()?.speed_test_dir,file_name); + let file_path = format!("{}{}",SERVER_CONFIG.get()?.assets_path,file_name); if let Ok(mut file) = File::open(file_path) { let mut file_bytes = Vec::new(); if file.read_to_end(&mut file_bytes).is_ok() { @@ -108,4 +108,4 @@ macro_rules! make_route { format!("{}{}",base_url,$a) } }; -} \ No newline at end of file +}