#![allow(dead_code)] use std::path::PathBuf; use serde::Deserialize; use url::Url; #[derive(Clone, Debug, Deserialize)] pub struct Config { /// legacy, maybe replace to did in future pub hostname: String, pub owner_did: String, pub listen_addr: String, /// path to store db, git-motd, etc pub data_dir: PathBuf, /// path to store git repositories pub data_repo_dir: PathBuf, pub plc_url: Url, pub jetstream_endpoint: Url, pub appview_endpoint: Url, pub git_user_name: String, pub git_user_email: String, // /// uhhhh do we need this? the default branch should be configured from user side // pub git_init_default_branch: String, } #[derive(Debug, Default, Deserialize)] pub struct ConfigBuilder { hostname: Option, // TODO: use DID type instead owner_did: Option, listen_addr: Option, data_dir: Option, data_repo_dir: Option, plc_url: Option, jetstream_endpoint: Option, appview_endpoint: Option, git_user_name: Option, git_user_email: Option, } // TODO(boltless): maybe use bon-rs instead impl ConfigBuilder { pub fn new(path: PathBuf) -> anyhow::Result { if path.is_file() { Ok(toml::from_str(&std::fs::read_to_string(&path)?)?) } else { Ok(Self::default()) } } pub fn build(self) -> anyhow::Result { Ok(Config { hostname: self.hostname.unwrap(), owner_did: self.owner_did.unwrap(), listen_addr: self.listen_addr.unwrap_or("0.0.0.0:5555".to_string()), data_dir: self.data_dir.unwrap_or("/home/git".into()), data_repo_dir: self.data_repo_dir.unwrap_or("/home/git".into()), plc_url: self .plc_url .unwrap_or_else(|| Url::parse("https://plc.directory").unwrap()), jetstream_endpoint: self.jetstream_endpoint.unwrap_or_else(|| { Url::parse("wss://jetstream1.us-west.bsky.network").unwrap() }), appview_endpoint: self .appview_endpoint .unwrap_or_else(|| Url::parse("https://tangled.org").unwrap()), git_user_name: self.git_user_name.unwrap_or("Tangled".to_string()), git_user_email: self .git_user_email .unwrap_or("noreply@tangled.org".to_string()), }) } }