move hardcoded dir path into config file

This commit is contained in:
aglkm
2024-05-10 14:00:39 +03:00
parent 91d4a780d7
commit e720f32c2f
3 changed files with 12 additions and 3 deletions

View File

@@ -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"

View File

@@ -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(),
}

View File

@@ -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<Mutex<Dashboard>>) -> Result<(), Error> {
// Collecting: disk_usage.
pub fn get_disk_usage(dashboard: Arc<Mutex<Dashboard>>) -> 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(())
}