]> Untitled Git - lemmy.git/blob - crates/utils/src/settings/structs.rs
Add feature to embed pictrs in lemmy binary (fixes #2627) (#2633)
[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   /// Settings related to activitypub federation
13   /// Pictrs image server configuration.
14   #[default(Some(Default::default()))]
15   pub(crate) pictrs: Option<PictrsConfig>,
16   /// Email sending configuration. All options except login/password are mandatory
17   #[default(None)]
18   #[doku(example = "Some(Default::default())")]
19   pub email: Option<EmailConfig>,
20   /// Parameters for automatic configuration of new instance (only used at first start)
21   #[default(None)]
22   #[doku(example = "Some(Default::default())")]
23   pub setup: Option<SetupConfig>,
24   /// the domain name of your instance (mandatory)
25   #[default("unset")]
26   #[doku(example = "example.com")]
27   pub hostname: String,
28   /// Address where lemmy should listen for incoming requests
29   #[default(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)))]
30   #[doku(as = "String")]
31   pub bind: IpAddr,
32   /// Port where lemmy should listen for incoming requests
33   #[default(8536)]
34   pub port: u16,
35   /// Whether the site is available over TLS. Needs to be true for federation to work.
36   #[default(true)]
37   pub tls_enabled: bool,
38   /// Set the URL for opentelemetry exports. If you do not have an opentelemetry collector, do not set this option
39   #[default(None)]
40   #[doku(skip)]
41   pub opentelemetry_url: Option<Url>,
42 }
43
44 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
45 #[serde(default)]
46 pub struct PictrsConfig {
47   /// Address where pictrs is available (for image hosting)
48   #[default(Url::parse("http://localhost:8080").expect("parse pictrs url"))]
49   #[doku(example = "http://localhost:8080")]
50   pub url: Url,
51
52   /// Set a custom pictrs API key. ( Required for deleting images )
53   #[default(None)]
54   pub api_key: Option<String>,
55 }
56
57 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
58 #[serde(default)]
59 pub struct DatabaseConfig {
60   /// Username to connect to postgres
61   #[default("lemmy")]
62   pub(super) user: String,
63   /// Password to connect to postgres
64   #[default("password")]
65   pub password: String,
66   #[default("localhost")]
67   /// Host where postgres is running
68   pub host: String,
69   /// Port where postgres can be accessed
70   #[default(5432)]
71   pub(super) port: i32,
72   /// Name of the postgres database for lemmy
73   #[default("lemmy")]
74   pub(super) database: String,
75   /// Maximum number of active sql connections
76   #[default(5)]
77   pub pool_size: u32,
78 }
79
80 #[derive(Debug, Deserialize, Serialize, Clone, Document, SmartDefault)]
81 pub struct EmailConfig {
82   /// Hostname and port of the smtp server
83   #[doku(example = "localhost:25")]
84   pub smtp_server: String,
85   /// Login name for smtp server
86   pub smtp_login: Option<String>,
87   /// Password to login to the smtp server
88   pub smtp_password: Option<String>,
89   #[doku(example = "noreply@example.com")]
90   /// Address to send emails from, eg "noreply@your-instance.com"
91   pub smtp_from_address: String,
92   /// Whether or not smtp connections should use tls. Can be none, tls, or starttls
93   #[default("none")]
94   #[doku(example = "none")]
95   pub tls_type: String,
96 }
97
98 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
99 pub struct SetupConfig {
100   /// Username for the admin user
101   #[doku(example = "admin")]
102   pub admin_username: String,
103   /// Password for the admin user. It must be at least 10 characters.
104   #[doku(example = "tf6HHDS4RolWfFhk4Rq9")]
105   pub admin_password: String,
106   /// Name of the site (can be changed later)
107   #[doku(example = "My Lemmy Instance")]
108   pub site_name: String,
109   /// Email for the admin user (optional, can be omitted and set later through the website)
110   #[doku(example = "user@example.com")]
111   #[default(None)]
112   pub admin_email: Option<String>,
113 }