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