2021-09-22 11:57:09 -04:00
|
|
|
use regex::Regex;
|
2021-03-01 12:24:11 -05:00
|
|
|
use serde::Deserialize;
|
2021-08-04 17:13:51 -04:00
|
|
|
use std::net::{IpAddr, Ipv4Addr};
|
2021-03-01 12:24:11 -05:00
|
|
|
|
2021-08-04 17:13:51 -04:00
|
|
|
#[derive(Debug, Deserialize, Clone, SmartDefault)]
|
|
|
|
#[serde(default)]
|
2021-03-01 12:24:11 -05:00
|
|
|
pub struct Settings {
|
2021-08-04 17:13:51 -04:00
|
|
|
#[serde(default)]
|
|
|
|
pub database: DatabaseConfig,
|
|
|
|
#[default(Some(RateLimitConfig::default()))]
|
|
|
|
pub rate_limit: Option<RateLimitConfig>,
|
|
|
|
#[default(FederationConfig::default())]
|
|
|
|
pub federation: FederationConfig,
|
|
|
|
#[default(CaptchaConfig::default())]
|
|
|
|
pub captcha: CaptchaConfig,
|
|
|
|
#[default(None)]
|
|
|
|
pub email: Option<EmailConfig>,
|
|
|
|
#[default(None)]
|
|
|
|
pub setup: Option<SetupConfig>,
|
|
|
|
#[default("unset")]
|
|
|
|
pub hostname: String,
|
|
|
|
#[default(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)))]
|
|
|
|
pub bind: IpAddr,
|
|
|
|
#[default(8536)]
|
|
|
|
pub port: u16,
|
|
|
|
#[default(true)]
|
|
|
|
pub tls_enabled: bool,
|
|
|
|
#[default(None)]
|
|
|
|
pub pictrs_url: Option<String>,
|
|
|
|
#[default(None)]
|
|
|
|
pub additional_slurs: Option<String>,
|
|
|
|
#[default(20)]
|
|
|
|
pub actor_name_max_length: usize,
|
2021-09-22 11:57:09 -04:00
|
|
|
#[default(None)]
|
|
|
|
#[serde(skip)]
|
|
|
|
pub webfinger_community_regex: Option<Regex>,
|
|
|
|
#[default(None)]
|
|
|
|
#[serde(skip)]
|
|
|
|
pub webfinger_username_regex: Option<Regex>,
|
2021-03-01 12:24:11 -05:00
|
|
|
}
|
|
|
|
|
2021-08-04 17:13:51 -04:00
|
|
|
#[derive(Debug, Deserialize, Clone, SmartDefault)]
|
|
|
|
#[serde(default)]
|
2021-03-01 12:24:11 -05:00
|
|
|
pub struct CaptchaConfig {
|
2021-08-04 17:13:51 -04:00
|
|
|
#[default(false)]
|
2021-03-01 12:24:11 -05:00
|
|
|
pub enabled: bool,
|
2021-08-04 17:13:51 -04:00
|
|
|
#[default("medium")]
|
2021-03-01 12:24:11 -05:00
|
|
|
pub difficulty: String,
|
|
|
|
}
|
|
|
|
|
2021-08-04 17:13:51 -04:00
|
|
|
#[derive(Debug, Deserialize, Clone, SmartDefault)]
|
|
|
|
#[serde(default)]
|
2021-03-01 12:24:11 -05:00
|
|
|
pub struct DatabaseConfig {
|
2021-08-04 17:13:51 -04:00
|
|
|
#[default("lemmy")]
|
|
|
|
pub(super) user: String,
|
|
|
|
#[default("password")]
|
2021-03-01 12:24:11 -05:00
|
|
|
pub password: String,
|
2021-08-04 17:13:51 -04:00
|
|
|
#[default("localhost")]
|
2021-03-01 12:24:11 -05:00
|
|
|
pub host: String,
|
2021-08-04 17:13:51 -04:00
|
|
|
#[default(5432)]
|
|
|
|
pub(super) port: i32,
|
|
|
|
#[default("lemmy")]
|
|
|
|
pub(super) database: String,
|
|
|
|
#[default(5)]
|
|
|
|
pub pool_size: u32,
|
2021-03-01 12:24:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
|
|
pub struct EmailConfig {
|
|
|
|
pub smtp_server: String,
|
|
|
|
pub smtp_login: Option<String>,
|
|
|
|
pub smtp_password: Option<String>,
|
|
|
|
pub smtp_from_address: String,
|
|
|
|
pub use_tls: bool,
|
|
|
|
}
|
|
|
|
|
2021-08-04 17:13:51 -04:00
|
|
|
#[derive(Debug, Deserialize, Clone, SmartDefault)]
|
|
|
|
#[serde(default)]
|
2021-03-01 12:24:11 -05:00
|
|
|
pub struct FederationConfig {
|
2021-08-04 17:13:51 -04:00
|
|
|
#[default(false)]
|
2021-03-01 12:24:11 -05:00
|
|
|
pub enabled: bool,
|
2021-08-04 17:13:51 -04:00
|
|
|
#[default(None)]
|
2021-03-01 12:24:11 -05:00
|
|
|
pub allowed_instances: Option<Vec<String>>,
|
2021-08-04 17:13:51 -04:00
|
|
|
#[default(None)]
|
2021-03-01 12:24:11 -05:00
|
|
|
pub blocked_instances: Option<Vec<String>>,
|
2021-08-04 17:13:51 -04:00
|
|
|
#[default(true)]
|
|
|
|
pub strict_allowlist: bool,
|
2021-03-01 12:24:11 -05:00
|
|
|
}
|
|
|
|
|
2021-08-04 17:13:51 -04:00
|
|
|
#[derive(Debug, Deserialize, Clone, SmartDefault)]
|
|
|
|
#[serde(default)]
|
2021-03-01 12:24:11 -05:00
|
|
|
pub struct RateLimitConfig {
|
2021-08-04 17:13:51 -04:00
|
|
|
#[default(180)]
|
2021-03-01 12:24:11 -05:00
|
|
|
pub message: i32,
|
2021-08-04 17:13:51 -04:00
|
|
|
#[default(60)]
|
2021-03-01 12:24:11 -05:00
|
|
|
pub message_per_second: i32,
|
2021-08-04 17:13:51 -04:00
|
|
|
#[default(6)]
|
2021-03-01 12:24:11 -05:00
|
|
|
pub post: i32,
|
2021-08-04 17:13:51 -04:00
|
|
|
#[default(600)]
|
2021-03-01 12:24:11 -05:00
|
|
|
pub post_per_second: i32,
|
2021-08-04 17:13:51 -04:00
|
|
|
#[default(3)]
|
2021-03-01 12:24:11 -05:00
|
|
|
pub register: i32,
|
2021-08-04 17:13:51 -04:00
|
|
|
#[default(3600)]
|
2021-03-01 12:24:11 -05:00
|
|
|
pub register_per_second: i32,
|
2021-08-04 17:13:51 -04:00
|
|
|
#[default(6)]
|
2021-03-01 12:24:11 -05:00
|
|
|
pub image: i32,
|
2021-08-04 17:13:51 -04:00
|
|
|
#[default(3600)]
|
2021-03-01 12:24:11 -05:00
|
|
|
pub image_per_second: i32,
|
|
|
|
}
|
|
|
|
|
2021-08-23 05:44:10 -04:00
|
|
|
#[derive(Debug, Deserialize, Clone, SmartDefault)]
|
2021-03-01 12:24:11 -05:00
|
|
|
pub struct SetupConfig {
|
|
|
|
pub admin_username: String,
|
|
|
|
pub admin_password: String,
|
|
|
|
pub site_name: String,
|
2021-08-23 05:44:10 -04:00
|
|
|
#[default(None)]
|
|
|
|
pub admin_email: Option<String>,
|
|
|
|
#[default(None)]
|
|
|
|
pub sidebar: Option<String>,
|
|
|
|
#[default(None)]
|
|
|
|
pub description: Option<String>,
|
|
|
|
#[default(None)]
|
|
|
|
pub icon: Option<String>,
|
|
|
|
#[default(None)]
|
|
|
|
pub banner: Option<String>,
|
|
|
|
#[default(None)]
|
|
|
|
pub enable_downvotes: Option<bool>,
|
|
|
|
#[default(None)]
|
|
|
|
pub open_registration: Option<bool>,
|
|
|
|
#[default(None)]
|
|
|
|
pub enable_nsfw: Option<bool>,
|
|
|
|
#[default(None)]
|
|
|
|
pub community_creation_admin_only: Option<bool>,
|
2021-03-01 12:24:11 -05:00
|
|
|
}
|