]> Untitled Git - lemmy.git/blob - crates/utils/src/settings/structs.rs
Add default post listing type (fixes #2195) (#2209)
[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   #[default(CaptchaConfig::default())]
18   pub captcha: CaptchaConfig,
19   /// Email sending configuration. All options except login/password are mandatory
20   #[default(None)]
21   pub email: Option<EmailConfig>,
22   /// Parameters for automatic configuration of new instance (only used at first start)
23   #[default(None)]
24   pub setup: Option<SetupConfig>,
25   /// the domain name of your instance (mandatory)
26   #[default("unset")]
27   #[doku(example = "example.com")]
28   pub hostname: String,
29   /// Address where lemmy should listen for incoming requests
30   #[default(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)))]
31   #[doku(as = "String")]
32   pub bind: IpAddr,
33   /// Port where lemmy should listen for incoming requests
34   #[default(8536)]
35   pub port: u16,
36   /// Whether the site is available over TLS. Needs to be true for federation to work.
37   #[default(true)]
38   pub tls_enabled: bool,
39   /// Address where pictrs is available (for image hosting)
40   #[default(None)]
41   #[doku(example = "http://localhost:8080")]
42   pub pictrs_url: Option<String>,
43   #[default(None)]
44   #[doku(example = "(\\bThis\\b)|(\\bis\\b)|(\\bsample\\b)")]
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 CaptchaConfig {
62   /// Whether captcha is required for signup
63   #[default(false)]
64   pub enabled: bool,
65   /// Can be easy, medium, or hard
66   #[default("medium")]
67   pub difficulty: String,
68 }
69
70 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
71 #[serde(default)]
72 pub struct DatabaseConfig {
73   /// Username to connect to postgres
74   #[default("lemmy")]
75   pub(super) user: String,
76   /// Password to connect to postgres
77   #[default("password")]
78   pub password: String,
79   #[default("localhost")]
80   /// Host where postgres is running
81   pub host: String,
82   /// Port where postgres can be accessed
83   #[default(5432)]
84   pub(super) port: i32,
85   /// Name of the postgres database for lemmy
86   #[default("lemmy")]
87   pub(super) database: String,
88   /// Maximum number of active sql connections
89   #[default(5)]
90   pub pool_size: u32,
91 }
92
93 #[derive(Debug, Deserialize, Serialize, Clone, Document, SmartDefault)]
94 pub struct EmailConfig {
95   /// Hostname and port of the smtp server
96   #[doku(example = "localhost:25")]
97   pub smtp_server: String,
98   /// Login name for smtp server
99   pub smtp_login: Option<String>,
100   /// Password to login to the smtp server
101   pub smtp_password: Option<String>,
102   #[doku(example = "noreply@example.com")]
103   /// Address to send emails from, eg "noreply@your-instance.com"
104   pub smtp_from_address: String,
105   /// Whether or not smtp connections should use tls. Can be none, tls, or starttls
106   #[default("none")]
107   #[doku(example = "none")]
108   pub tls_type: String,
109 }
110
111 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
112 #[serde(default)]
113 pub struct FederationConfig {
114   /// Whether to enable activitypub federation.
115   #[default(false)]
116   pub enabled: bool,
117   /// Allows and blocks are described here:
118   /// https://join-lemmy.org/docs/en/administration/federation_getting_started.html
119   ///
120   /// list of instances with which federation is allowed
121   #[default(None)]
122   #[doku(example = "instance1.tld")]
123   #[doku(example = "instance2.tld")]
124   pub allowed_instances: Option<Vec<String>>,
125   /// Instances which we never federate anything with (but previously federated objects are unaffected)
126   #[default(None)]
127   pub blocked_instances: Option<Vec<String>>,
128   /// If true, only federate with instances on the allowlist and block everything else. If false,
129   /// use allowlist only for remote communities, and posts/comments in local communities
130   /// (meaning remote communities will show content from arbitrary instances).
131   #[default(true)]
132   pub strict_allowlist: bool,
133   /// Number of workers for sending outgoing activities. Search logs for "Activity queue stats" to
134   /// see information. If "running" number is consistently close to the worker_count, you should
135   /// increase it.
136   #[default(64)]
137   pub worker_count: u64,
138 }
139
140 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
141 #[serde(default)]
142 pub struct RateLimitConfig {
143   /// Maximum number of messages created in interval
144   #[default(180)]
145   pub message: i32,
146   /// Interval length for message limit, in seconds
147   #[default(60)]
148   pub message_per_second: i32,
149   /// Maximum number of posts created in interval
150   #[default(6)]
151   pub post: i32,
152   /// Interval length for post limit, in seconds
153   #[default(600)]
154   pub post_per_second: i32,
155   /// Maximum number of registrations in interval
156   #[default(3)]
157   pub register: i32,
158   /// Interval length for registration limit, in seconds
159   #[default(3600)]
160   pub register_per_second: i32,
161   /// Maximum number of image uploads in interval
162   #[default(6)]
163   pub image: i32,
164   /// Interval length for image uploads, in seconds
165   #[default(3600)]
166   pub image_per_second: i32,
167   /// Maximum number of comments created in interval
168   #[default(6)]
169   pub comment: i32,
170   /// Interval length for comment limit, in seconds
171   #[default(600)]
172   pub comment_per_second: i32,
173   #[default(6)]
174   pub search: i32,
175   /// Interval length for search limit, in seconds
176   #[default(600)]
177   pub search_per_second: i32,
178 }
179
180 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
181 pub struct SetupConfig {
182   /// Username for the admin user
183   #[doku(example = "admin")]
184   pub admin_username: String,
185   /// Password for the admin user. It must be at least 10 characters.
186   #[doku(example = "my_passwd_longer_than_ten_characters")]
187   pub admin_password: String,
188   /// Name of the site (can be changed later)
189   #[doku(example = "My Lemmy Instance")]
190   pub site_name: String,
191   /// Email for the admin user (optional, can be omitted and set later through the website)
192   #[default(None)]
193   pub admin_email: Option<String>,
194   #[default(None)]
195   pub sidebar: Option<String>,
196   #[default(None)]
197   pub description: Option<String>,
198   #[default(None)]
199   pub icon: Option<String>,
200   #[default(None)]
201   pub banner: Option<String>,
202   #[default(None)]
203   pub enable_downvotes: Option<bool>,
204   #[default(None)]
205   pub open_registration: Option<bool>,
206   #[default(None)]
207   pub enable_nsfw: Option<bool>,
208   #[default(None)]
209   pub community_creation_admin_only: Option<bool>,
210   #[default(None)]
211   pub require_email_verification: Option<bool>,
212   #[default(None)]
213   pub require_application: Option<bool>,
214   #[default(None)]
215   pub application_question: Option<String>,
216   #[default(None)]
217   pub private_instance: Option<bool>,
218   #[default(None)]
219   pub default_theme: Option<String>,
220   #[default(None)]
221   pub default_post_listing_type: Option<String>,
222 }