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>,
20 pub(crate) additional_slurs: Option<String>,
23 #[derive(Debug, Deserialize, Clone)]
24 pub struct CaptchaConfig {
26 pub difficulty: String,
29 #[derive(Debug, Deserialize, Clone)]
30 pub struct DatabaseConfig {
31 pub(super) user: Option<String>,
34 pub(super) port: Option<i32>,
35 pub(super) database: Option<String>,
36 pub(super) pool_size: Option<u32>,
40 pub fn user(&self) -> String {
44 .unwrap_or_else(|| DatabaseConfig::default().user.expect("missing user"))
46 pub fn port(&self) -> i32 {
49 .unwrap_or_else(|| DatabaseConfig::default().port.expect("missing port"))
51 pub fn database(&self) -> String {
52 self.database.to_owned().unwrap_or_else(|| {
53 DatabaseConfig::default()
55 .expect("missing database")
58 pub fn pool_size(&self) -> u32 {
59 self.pool_size.unwrap_or_else(|| {
60 DatabaseConfig::default()
62 .expect("missing pool_size")
67 #[derive(Debug, Deserialize, Clone)]
68 pub struct EmailConfig {
69 pub smtp_server: String,
70 pub smtp_login: Option<String>,
71 pub smtp_password: Option<String>,
72 pub smtp_from_address: String,
76 #[derive(Debug, Deserialize, Clone)]
77 pub struct FederationConfig {
79 pub allowed_instances: Option<Vec<String>>,
80 pub blocked_instances: Option<Vec<String>>,
81 pub strict_allowlist: Option<bool>,
84 #[derive(Debug, Deserialize, Clone)]
85 pub struct RateLimitConfig {
87 pub message_per_second: i32,
89 pub post_per_second: i32,
91 pub register_per_second: i32,
93 pub image_per_second: i32,
96 #[derive(Debug, Deserialize, Clone)]
97 pub struct SetupConfig {
98 pub admin_username: String,
99 pub admin_password: String,
100 pub admin_email: Option<String>,
101 pub site_name: String,