From e720f32c2f3e345728ffe129e6eeffbae7a27506 Mon Sep 17 00:00:00 2001 From: aglkm <39521015+aglkm@users.noreply.github.com> Date: Fri, 10 May 2024 14:00:39 +0300 Subject: [PATCH] move hardcoded dir path into config file --- Explorer.toml | 3 +++ src/data.rs | 2 ++ src/requests.rs | 10 +++++++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Explorer.toml b/Explorer.toml index 6e9e95e..95a7c76 100644 --- a/Explorer.toml +++ b/Explorer.toml @@ -16,3 +16,6 @@ api_secret_path = "~/.grin/main/.api_secret" # Foreign API secret path. foreign_api_secret_path = "~/.grin/main/.foreign_api_secret" +# Path to Grin directory +grin_dir = "~/.grin" + diff --git a/src/data.rs b/src/data.rs index da4d1b8..a8a462c 100644 --- a/src/data.rs +++ b/src/data.rs @@ -138,6 +138,7 @@ pub struct ExplorerConfig { pub user: String, pub api_secret_path: String, pub foreign_api_secret_path: String, + pub grin_dir: String, pub api_secret: String, pub foreign_api_secret: String, } @@ -151,6 +152,7 @@ impl ExplorerConfig { user: String::new(), api_secret_path: String::new(), foreign_api_secret_path: String::new(), + grin_dir: String::new(), api_secret: String::new(), foreign_api_secret: String::new(), } diff --git a/src/requests.rs b/src/requests.rs index 9960c14..b758888 100644 --- a/src/requests.rs +++ b/src/requests.rs @@ -35,6 +35,7 @@ lazy_static! { "user" => cfg.user = value, "api_secret_path" => cfg.api_secret_path = value, "foreign_api_secret_path" => cfg.foreign_api_secret_path = value, + "grin_dir" => cfg.grin_dir = value, _ => println!("{} Unknown config setting '{}'.", "[ ERROR ]".red(), name), } } @@ -43,7 +44,8 @@ lazy_static! { shellexpand::tilde(&cfg.api_secret_path))).unwrap(); cfg.foreign_api_secret = fs::read_to_string(format!("{}", shellexpand::tilde(&cfg.foreign_api_secret_path))).unwrap(); - + cfg.grin_dir = format!("{}", shellexpand::tilde(&cfg.grin_dir)); + cfg }; } @@ -187,9 +189,11 @@ pub async fn get_market(dashboard: Arc>) -> Result<(), Error> { // Collecting: disk_usage. pub fn get_disk_usage(dashboard: Arc>) -> Result<(), Error> { let mut data = dashboard.lock().unwrap(); - let grin_dir = format!("{}/.grin", std::env::var("HOME").unwrap()); - data.disk_usage = format!("{:.2}", (get_size(grin_dir).unwrap() as f64) / 1000.0 / 1000.0 / 1000.0); + let chain_data = format!("{}/main/chain_data", CONFIG.grin_dir); + + data.disk_usage = format!("{:.2}", (get_size(chain_data).unwrap() as f64) + / 1000.0 / 1000.0 / 1000.0); Ok(()) }