]> Untitled Git - lemmy.git/blob - crates/utils/src/settings/structs.rs
Merge pull request #1917 from LemmyNet/outbox-announce
[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 }
50
51 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
52 #[serde(default)]
53 pub struct CaptchaConfig {
54   /// Whether captcha is required for signup
55   #[default(false)]
56   pub enabled: bool,
57   /// Can be easy, medium, or hard
58   #[default("medium")]
59   pub difficulty: String,
60 }
61
62 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
63 #[serde(default)]
64 pub struct DatabaseConfig {
65   /// Username to connect to postgres
66   #[default("lemmy")]
67   pub(super) user: String,
68   /// Password to connect to postgres
69   #[default("password")]
70   pub password: String,
71   #[default("localhost")]
72   /// Host where postgres is running
73   pub host: String,
74   /// Port where postgres can be accessed
75   #[default(5432)]
76   pub(super) port: i32,
77   /// Name of the postgres database for lemmy
78   #[default("lemmy")]
79   pub(super) database: String,
80   /// Maximum number of active sql connections
81   #[default(5)]
82   pub pool_size: u32,
83 }
84
85 #[derive(Debug, Deserialize, Serialize, Clone, Document)]
86 pub struct EmailConfig {
87   /// Hostname and port of the smtp server
88   #[doku(example = "localhost:25")]
89   pub smtp_server: String,
90   /// Login name for smtp server
91   pub smtp_login: Option<String>,
92   /// Password to login to the smtp server
93   pub smtp_password: Option<String>,
94   #[doku(example = "noreply@example.com")]
95   /// Address to send emails from, eg "noreply@your-instance.com"
96   pub smtp_from_address: String,
97   /// Whether or not smtp connections should use tls
98   pub use_tls: bool,
99 }
100
101 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
102 #[serde(default)]
103 pub struct FederationConfig {
104   /// Whether to enable activitypub federation.
105   #[default(false)]
106   pub enabled: bool,
107   /// Allows and blocks are described here:
108   /// https://join-lemmy.org/docs/en/federation/administration.html///instance-allowlist-and-blocklist
109   ///
110   /// list of instances with which federation is allowed
111   #[default(None)]
112   #[doku(example = "instance1.tld")]
113   #[doku(example = "instance2.tld")]
114   pub allowed_instances: Option<Vec<String>>,
115   /// Instances which we never federate anything with (but previously federated objects are unaffected)
116   #[default(None)]
117   pub blocked_instances: Option<Vec<String>>,
118   /// If true, only federate with instances on the allowlist and block everything else. If false,
119   /// use allowlist only for remote communities, and posts/comments in local communities
120   /// (meaning remote communities will show content from arbitrary instances).
121   #[default(true)]
122   pub strict_allowlist: bool,
123 }
124
125 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
126 #[serde(default)]
127 pub struct RateLimitConfig {
128   /// Maximum number of messages created in interval
129   #[default(180)]
130   pub message: i32,
131   /// Interval length for message limit, in seconds
132   #[default(60)]
133   pub message_per_second: i32,
134   /// Maximum number of posts created in interval
135   #[default(6)]
136   pub post: i32,
137   /// Interval length for post limit, in seconds
138   #[default(600)]
139   pub post_per_second: i32,
140   /// Maximum number of registrations in interval
141   #[default(3)]
142   pub register: i32,
143   /// Interval length for registration limit, in seconds
144   #[default(3600)]
145   pub register_per_second: i32,
146   /// Maximum number of image uploads in interval
147   #[default(6)]
148   pub image: i32,
149   /// Interval length for image uploads, in seconds
150   #[default(3600)]
151   pub image_per_second: i32,
152   /// Maximum number of comments created in interval
153   #[default(6)]
154   pub comment: i32,
155   /// Interval length for comment limit, in seconds
156   #[default(600)]
157   pub comment_per_second: i32,
158 }
159
160 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
161 pub struct SetupConfig {
162   /// Username for the admin user
163   #[doku(example = "admin")]
164   pub admin_username: String,
165   /// Password for the admin user
166   #[doku(example = "my_passwd")]
167   pub admin_password: String,
168   /// Name of the site (can be changed later)
169   #[doku(example = "My Lemmy Instance")]
170   pub site_name: String,
171   /// Email for the admin user (optional, can be omitted and set later through the website)
172   #[default(None)]
173   pub admin_email: Option<String>,
174   #[default(None)]
175   pub sidebar: Option<String>,
176   #[default(None)]
177   pub description: Option<String>,
178   #[default(None)]
179   pub icon: Option<String>,
180   #[default(None)]
181   pub banner: Option<String>,
182   #[default(None)]
183   pub enable_downvotes: Option<bool>,
184   #[default(None)]
185   pub open_registration: Option<bool>,
186   #[default(None)]
187   pub enable_nsfw: Option<bool>,
188   #[default(None)]
189   pub community_creation_admin_only: Option<bool>,
190 }