2 use serde::Deserialize;
5 #[derive(Debug, Deserialize, Clone, Merge)]
7 pub(crate) database: Option<DatabaseConfig>,
8 pub(crate) rate_limit: Option<RateLimitConfig>,
9 pub(crate) federation: Option<FederationConfig>,
10 pub(crate) hostname: Option<String>,
11 pub(crate) bind: Option<IpAddr>,
12 pub(crate) port: Option<u16>,
13 pub(crate) tls_enabled: Option<bool>,
14 pub(crate) jwt_secret: Option<String>,
15 pub(crate) pictrs_url: Option<String>,
16 pub(crate) iframely_url: Option<String>,
17 pub(crate) captcha: Option<CaptchaConfig>,
18 pub(crate) email: Option<EmailConfig>,
19 pub(crate) setup: Option<SetupConfig>,
22 #[derive(Debug, Deserialize, Clone)]
23 pub struct CaptchaConfig {
25 pub difficulty: String,
28 #[derive(Debug, Deserialize, Clone)]
29 pub struct DatabaseConfig {
30 pub(super) user: Option<String>,
33 pub(super) port: Option<i32>,
34 pub(super) database: Option<String>,
35 pub(super) pool_size: Option<u32>,
39 pub fn user(&self) -> String {
43 .unwrap_or_else(|| DatabaseConfig::default().user.expect("missing user"))
45 pub fn port(&self) -> i32 {
48 .unwrap_or_else(|| DatabaseConfig::default().port.expect("missing port"))
50 pub fn database(&self) -> String {
51 self.database.to_owned().unwrap_or_else(|| {
52 DatabaseConfig::default()
54 .expect("missing database")
57 pub fn pool_size(&self) -> u32 {
58 self.pool_size.unwrap_or_else(|| {
59 DatabaseConfig::default()
61 .expect("missing pool_size")
66 #[derive(Debug, Deserialize, Clone)]
67 pub struct EmailConfig {
68 pub smtp_server: String,
69 pub smtp_login: Option<String>,
70 pub smtp_password: Option<String>,
71 pub smtp_from_address: String,
75 #[derive(Debug, Deserialize, Clone)]
76 pub struct FederationConfig {
78 pub allowed_instances: Option<Vec<String>>,
79 pub blocked_instances: Option<Vec<String>>,
82 #[derive(Debug, Deserialize, Clone)]
83 pub struct RateLimitConfig {
85 pub message_per_second: i32,
87 pub post_per_second: i32,
89 pub register_per_second: i32,
91 pub image_per_second: i32,
94 #[derive(Debug, Deserialize, Clone)]
95 pub struct SetupConfig {
96 pub admin_username: String,
97 pub admin_password: String,
98 pub admin_email: Option<String>,
99 pub site_name: String,