use merge::Merge; use serde::Deserialize; use std::net::IpAddr; #[derive(Debug, Deserialize, Clone, Merge)] pub struct Settings { pub(crate) database: Option, pub(crate) rate_limit: Option, pub(crate) federation: Option, pub(crate) hostname: Option, pub(crate) bind: Option, pub(crate) port: Option, pub(crate) tls_enabled: Option, pub(crate) jwt_secret: Option, pub(crate) pictrs_url: Option, pub(crate) iframely_url: Option, pub(crate) captcha: Option, pub(crate) email: Option, pub(crate) setup: Option, pub(crate) additional_slurs: Option, } #[derive(Debug, Deserialize, Clone)] pub struct CaptchaConfig { pub enabled: bool, pub difficulty: String, } #[derive(Debug, Deserialize, Clone)] pub struct DatabaseConfig { pub(super) user: Option, pub password: String, pub host: String, pub(super) port: Option, pub(super) database: Option, pub(super) pool_size: Option, } impl DatabaseConfig { pub fn user(&self) -> String { self .user .to_owned() .unwrap_or_else(|| DatabaseConfig::default().user.expect("missing user")) } pub fn port(&self) -> i32 { self .port .unwrap_or_else(|| DatabaseConfig::default().port.expect("missing port")) } pub fn database(&self) -> String { self.database.to_owned().unwrap_or_else(|| { DatabaseConfig::default() .database .expect("missing database") }) } pub fn pool_size(&self) -> u32 { self.pool_size.unwrap_or_else(|| { DatabaseConfig::default() .pool_size .expect("missing pool_size") }) } } #[derive(Debug, Deserialize, Clone)] pub struct EmailConfig { pub smtp_server: String, pub smtp_login: Option, pub smtp_password: Option, pub smtp_from_address: String, pub use_tls: bool, } #[derive(Debug, Deserialize, Clone)] pub struct FederationConfig { pub enabled: bool, pub allowed_instances: Option>, pub blocked_instances: Option>, pub strict_allowlist: Option, } #[derive(Debug, Deserialize, Clone)] pub struct RateLimitConfig { pub message: i32, pub message_per_second: i32, pub post: i32, pub post_per_second: i32, pub register: i32, pub register_per_second: i32, pub image: i32, pub image_per_second: i32, } #[derive(Debug, Deserialize, Clone)] pub struct SetupConfig { pub admin_username: String, pub admin_password: String, pub admin_email: Option, pub site_name: String, }