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