1 pub mod constants;
2
3 use anyhow::{anyhow, Result};
4 use log::debug;
5 use smbpndk_model::Config;
6
7 pub async fn get_token() -> Result<String> {
8 if let Some(mut path) = dirs::home_dir() {
9 path.push(".smb/token");
10 std::fs::read_to_string(path).map_err(|e| {
11 debug!("Error while reading token: {}", &e);
12 anyhow!("Error while reading token. Are you logged in?")
13 })
14 } else {
15 Err(anyhow!("Failed to get home directory."))
16 }
17 }
18
19 pub async fn get_config() -> Result<Config> {
20 match dirs::home_dir() {
21 Some(mut path) => {
22 path.push(".smb/config");
23 let config = std::fs::read_to_string(path)?;
24 let config: Config = serde_json::from_str(&config)?;
25 Ok(config)
26 }
27 None => Err(anyhow!("Failed to get home directory.")),
28 }
29 }