]> Untitled Git - lemmy.git/blob - crates/utils/src/settings/structs.rs
Rewrite fetcher (#1792)
[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 additional_slurs: Option<String>,
33   #[default(20)]
34   pub actor_name_max_length: usize,
35 }
36
37 #[derive(Debug, Deserialize, Clone, SmartDefault)]
38 #[serde(default)]
39 pub struct CaptchaConfig {
40   #[default(false)]
41   pub enabled: bool,
42   #[default("medium")]
43   pub difficulty: String,
44 }
45
46 #[derive(Debug, Deserialize, Clone, SmartDefault)]
47 #[serde(default)]
48 pub struct DatabaseConfig {
49   #[default("lemmy")]
50   pub(super) user: String,
51   #[default("password")]
52   pub password: String,
53   #[default("localhost")]
54   pub host: String,
55   #[default(5432)]
56   pub(super) port: i32,
57   #[default("lemmy")]
58   pub(super) database: String,
59   #[default(5)]
60   pub pool_size: u32,
61 }
62
63 #[derive(Debug, Deserialize, Clone)]
64 pub struct EmailConfig {
65   pub smtp_server: String,
66   pub smtp_login: Option<String>,
67   pub smtp_password: Option<String>,
68   pub smtp_from_address: String,
69   pub use_tls: bool,
70 }
71
72 #[derive(Debug, Deserialize, Clone, SmartDefault)]
73 #[serde(default)]
74 pub struct FederationConfig {
75   #[default(false)]
76   pub enabled: bool,
77   #[default(None)]
78   pub allowed_instances: Option<Vec<String>>,
79   #[default(None)]
80   pub blocked_instances: Option<Vec<String>>,
81   #[default(true)]
82   pub strict_allowlist: bool,
83 }
84
85 #[derive(Debug, Deserialize, Clone, SmartDefault)]
86 #[serde(default)]
87 pub struct RateLimitConfig {
88   #[default(180)]
89   pub message: i32,
90   #[default(60)]
91   pub message_per_second: i32,
92   #[default(6)]
93   pub post: i32,
94   #[default(600)]
95   pub post_per_second: i32,
96   #[default(3)]
97   pub register: i32,
98   #[default(3600)]
99   pub register_per_second: i32,
100   #[default(6)]
101   pub image: i32,
102   #[default(3600)]
103   pub image_per_second: i32,
104 }
105
106 #[derive(Debug, Deserialize, Clone, SmartDefault)]
107 pub struct SetupConfig {
108   pub admin_username: String,
109   pub admin_password: String,
110   pub site_name: String,
111   #[default(None)]
112   pub admin_email: Option<String>,
113   #[default(None)]
114   pub sidebar: Option<String>,
115   #[default(None)]
116   pub description: Option<String>,
117   #[default(None)]
118   pub icon: Option<String>,
119   #[default(None)]
120   pub banner: Option<String>,
121   #[default(None)]
122   pub enable_downvotes: Option<bool>,
123   #[default(None)]
124   pub open_registration: Option<bool>,
125   #[default(None)]
126   pub enable_nsfw: Option<bool>,
127   #[default(None)]
128   pub community_creation_admin_only: Option<bool>,
129 }