]> Untitled Git - lemmy.git/blob - crates/utils/src/settings/structs.rs
Simplify config using macros (#1686)
[lemmy.git] / crates / utils / src / settings / structs.rs
1 use serde::Deserialize;
2 use std::net::{IpAddr, Ipv4Addr};
3
4 #[derive(Debug, Deserialize, Clone, SmartDefault)]
5 #[serde(default)]
6 pub struct Settings {
7   #[serde(default)]
8   pub database: DatabaseConfig,
9   #[default(Some(RateLimitConfig::default()))]
10   pub rate_limit: Option<RateLimitConfig>,
11   #[default(FederationConfig::default())]
12   pub federation: FederationConfig,
13   #[default(CaptchaConfig::default())]
14   pub captcha: CaptchaConfig,
15   #[default(None)]
16   pub email: Option<EmailConfig>,
17   #[default(None)]
18   pub setup: Option<SetupConfig>,
19   #[default("unset")]
20   pub hostname: String,
21   #[default(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)))]
22   pub bind: IpAddr,
23   #[default(8536)]
24   pub port: u16,
25   #[default(true)]
26   pub tls_enabled: bool,
27   #[default("changeme")]
28   pub jwt_secret: String,
29   #[default(None)]
30   pub pictrs_url: Option<String>,
31   #[default(None)]
32   pub iframely_url: Option<String>,
33   #[default(None)]
34   pub additional_slurs: Option<String>,
35   #[default(20)]
36   pub actor_name_max_length: usize,
37 }
38
39 #[derive(Debug, Deserialize, Clone, SmartDefault)]
40 #[serde(default)]
41 pub struct CaptchaConfig {
42   #[default(false)]
43   pub enabled: bool,
44   #[default("medium")]
45   pub difficulty: String,
46 }
47
48 #[derive(Debug, Deserialize, Clone, SmartDefault)]
49 #[serde(default)]
50 pub struct DatabaseConfig {
51   #[default("lemmy")]
52   pub(super) user: String,
53   #[default("password")]
54   pub password: String,
55   #[default("localhost")]
56   pub host: String,
57   #[default(5432)]
58   pub(super) port: i32,
59   #[default("lemmy")]
60   pub(super) database: String,
61   #[default(5)]
62   pub pool_size: u32,
63 }
64
65 #[derive(Debug, Deserialize, Clone)]
66 pub struct EmailConfig {
67   pub smtp_server: String,
68   pub smtp_login: Option<String>,
69   pub smtp_password: Option<String>,
70   pub smtp_from_address: String,
71   pub use_tls: bool,
72 }
73
74 #[derive(Debug, Deserialize, Clone, SmartDefault)]
75 #[serde(default)]
76 pub struct FederationConfig {
77   #[default(false)]
78   pub enabled: bool,
79   #[default(None)]
80   pub allowed_instances: Option<Vec<String>>,
81   #[default(None)]
82   pub blocked_instances: Option<Vec<String>>,
83   #[default(true)]
84   pub strict_allowlist: bool,
85 }
86
87 #[derive(Debug, Deserialize, Clone, SmartDefault)]
88 #[serde(default)]
89 pub struct RateLimitConfig {
90   #[default(180)]
91   pub message: i32,
92   #[default(60)]
93   pub message_per_second: i32,
94   #[default(6)]
95   pub post: i32,
96   #[default(600)]
97   pub post_per_second: i32,
98   #[default(3)]
99   pub register: i32,
100   #[default(3600)]
101   pub register_per_second: i32,
102   #[default(6)]
103   pub image: i32,
104   #[default(3600)]
105   pub image_per_second: i32,
106 }
107
108 #[derive(Debug, Deserialize, Clone)]
109 pub struct SetupConfig {
110   pub admin_username: String,
111   pub admin_password: String,
112   pub admin_email: Option<String>,
113   pub site_name: String,
114 }