]> Untitled Git - lemmy.git/blob - crates/utils/src/settings/structs.rs
d6846f18551b8ef3d8688d55c5c1965ef881f035
[lemmy.git] / crates / utils / src / settings / structs.rs
1 use doku::Document;
2 use serde::{Deserialize, Serialize};
3 use std::net::{IpAddr, Ipv4Addr};
4
5 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
6 #[serde(default)]
7 pub struct Settings {
8   /// settings related to the postgresql database
9   #[serde(default)]
10   pub database: DatabaseConfig,
11   #[default(Some(RateLimitConfig::default()))]
12   /// rate limits for various user actions, by user ip
13   pub rate_limit: Option<RateLimitConfig>,
14   /// Settings related to activitypub federation
15   #[default(FederationConfig::default())]
16   pub federation: FederationConfig,
17   /// Pictrs image server configuration.
18   #[default(None)]
19   pub(crate) pictrs_config: Option<PictrsConfig>,
20   #[default(CaptchaConfig::default())]
21   pub captcha: CaptchaConfig,
22   /// Email sending configuration. All options except login/password are mandatory
23   #[default(None)]
24   pub email: Option<EmailConfig>,
25   /// Parameters for automatic configuration of new instance (only used at first start)
26   #[default(None)]
27   pub setup: Option<SetupConfig>,
28   /// the domain name of your instance (mandatory)
29   #[default("unset")]
30   #[doku(example = "example.com")]
31   pub hostname: String,
32   /// Address where lemmy should listen for incoming requests
33   #[default(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)))]
34   #[doku(as = "String")]
35   pub bind: IpAddr,
36   /// Port where lemmy should listen for incoming requests
37   #[default(8536)]
38   pub port: u16,
39   /// Whether the site is available over TLS. Needs to be true for federation to work.
40   #[default(true)]
41   pub tls_enabled: bool,
42   #[default(None)]
43   #[doku(example = "(\\bThis\\b)|(\\bis\\b)|(\\bsample\\b)")]
44   /// A regex list of slurs to block / hide
45   pub slur_filter: Option<String>,
46   /// Maximum length of local community and user names
47   #[default(20)]
48   pub actor_name_max_length: usize,
49   /// Maximum number of HTTP requests allowed to handle a single incoming activity (or a single object fetch through the search).
50   #[default(25)]
51   pub http_fetch_retry_limit: i32,
52
53   /// Set the URL for opentelemetry exports. If you do not have an opentelemetry collector, do not set this option
54   #[default(None)]
55   #[doku(skip)]
56   pub opentelemetry_url: Option<String>,
57 }
58
59 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
60 #[serde(default)]
61 pub struct PictrsConfig {
62   /// Address where pictrs is available (for image hosting)
63   #[default("http://pictrs:8080")]
64   pub url: String,
65
66   /// Set a custom pictrs API key. ( Required for deleting images )
67   #[default("API_KEY")]
68   pub api_key: String,
69 }
70
71 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
72 #[serde(default)]
73 pub struct CaptchaConfig {
74   /// Whether captcha is required for signup
75   #[default(false)]
76   pub enabled: bool,
77   /// Can be easy, medium, or hard
78   #[default("medium")]
79   pub difficulty: String,
80 }
81
82 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
83 #[serde(default)]
84 pub struct DatabaseConfig {
85   /// Username to connect to postgres
86   #[default("lemmy")]
87   pub(super) user: String,
88   /// Password to connect to postgres
89   #[default("password")]
90   pub password: String,
91   #[default("localhost")]
92   /// Host where postgres is running
93   pub host: String,
94   /// Port where postgres can be accessed
95   #[default(5432)]
96   pub(super) port: i32,
97   /// Name of the postgres database for lemmy
98   #[default("lemmy")]
99   pub(super) database: String,
100   /// Maximum number of active sql connections
101   #[default(5)]
102   pub pool_size: u32,
103 }
104
105 #[derive(Debug, Deserialize, Serialize, Clone, Document, SmartDefault)]
106 pub struct EmailConfig {
107   /// Hostname and port of the smtp server
108   #[doku(example = "localhost:25")]
109   pub smtp_server: String,
110   /// Login name for smtp server
111   pub smtp_login: Option<String>,
112   /// Password to login to the smtp server
113   pub smtp_password: Option<String>,
114   #[doku(example = "noreply@example.com")]
115   /// Address to send emails from, eg "noreply@your-instance.com"
116   pub smtp_from_address: String,
117   /// Whether or not smtp connections should use tls. Can be none, tls, or starttls
118   #[default("none")]
119   #[doku(example = "none")]
120   pub tls_type: String,
121 }
122
123 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
124 #[serde(default)]
125 pub struct FederationConfig {
126   /// Whether to enable activitypub federation.
127   #[default(false)]
128   pub enabled: bool,
129   /// Allows and blocks are described here:
130   /// https://join-lemmy.org/docs/en/administration/federation_getting_started.html
131   ///
132   /// list of instances with which federation is allowed
133   #[default(None)]
134   #[doku(example = "instance1.tld")]
135   #[doku(example = "instance2.tld")]
136   pub allowed_instances: Option<Vec<String>>,
137   /// Instances which we never federate anything with (but previously federated objects are unaffected)
138   #[default(None)]
139   pub blocked_instances: Option<Vec<String>>,
140   /// If true, only federate with instances on the allowlist and block everything else. If false,
141   /// use allowlist only for remote communities, and posts/comments in local communities
142   /// (meaning remote communities will show content from arbitrary instances).
143   #[default(true)]
144   pub strict_allowlist: bool,
145   /// Number of workers for sending outgoing activities. Search logs for "Activity queue stats" to
146   /// see information. If "running" number is consistently close to the worker_count, you should
147   /// increase it.
148   #[default(64)]
149   pub worker_count: u64,
150   /// Use federation debug mode. Allows connecting to http and localhost urls. Also sends outgoing
151   /// activities synchronously for easier testing. Do not use in production.
152   #[default(false)]
153   pub debug: bool,
154 }
155
156 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
157 #[serde(default)]
158 pub struct RateLimitConfig {
159   /// Maximum number of messages created in interval
160   #[default(180)]
161   pub message: i32,
162   /// Interval length for message limit, in seconds
163   #[default(60)]
164   pub message_per_second: i32,
165   /// Maximum number of posts created in interval
166   #[default(6)]
167   pub post: i32,
168   /// Interval length for post limit, in seconds
169   #[default(600)]
170   pub post_per_second: i32,
171   /// Maximum number of registrations in interval
172   #[default(3)]
173   pub register: i32,
174   /// Interval length for registration limit, in seconds
175   #[default(3600)]
176   pub register_per_second: i32,
177   /// Maximum number of image uploads in interval
178   #[default(6)]
179   pub image: i32,
180   /// Interval length for image uploads, in seconds
181   #[default(3600)]
182   pub image_per_second: i32,
183   /// Maximum number of comments created in interval
184   #[default(6)]
185   pub comment: i32,
186   /// Interval length for comment limit, in seconds
187   #[default(600)]
188   pub comment_per_second: i32,
189   #[default(6)]
190   pub search: i32,
191   /// Interval length for search limit, in seconds
192   #[default(600)]
193   pub search_per_second: i32,
194 }
195
196 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
197 pub struct SetupConfig {
198   /// Username for the admin user
199   #[doku(example = "admin")]
200   pub admin_username: String,
201   /// Password for the admin user. It must be at least 10 characters.
202   #[doku(example = "tf6HHDS4RolWfFhk4Rq9")]
203   pub admin_password: String,
204   /// Name of the site (can be changed later)
205   #[doku(example = "My Lemmy Instance")]
206   pub site_name: String,
207   /// Email for the admin user (optional, can be omitted and set later through the website)
208   #[doku(example = "user@example.com")]
209   #[default(None)]
210   pub admin_email: Option<String>,
211 }