2023-12-11 15:18:43 +00:00
|
|
|
use anyhow::Error;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use tokio::fs::read_to_string;
|
|
|
|
|
2024-02-25 16:26:39 +00:00
|
|
|
#[derive(Deserialize, Debug, Clone)]
|
2023-12-11 15:18:43 +00:00
|
|
|
pub struct Cfg {
|
|
|
|
pub server: ServerCfg,
|
|
|
|
pub site: SiteCfg,
|
|
|
|
pub secrets: SecretsCfg,
|
|
|
|
pub files: FilesCfg,
|
|
|
|
pub board_defaults: BoardCfg,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Cfg {
|
|
|
|
pub async fn load(path: &str) -> Result<Self, Error> {
|
|
|
|
let cfg_string = read_to_string(path).await?;
|
|
|
|
let cfg: Cfg = toml::from_str(&cfg_string)?;
|
|
|
|
|
|
|
|
Ok(cfg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-25 16:26:39 +00:00
|
|
|
#[derive(Deserialize, Debug, Clone)]
|
2023-12-11 15:18:43 +00:00
|
|
|
pub struct ServerCfg {
|
|
|
|
pub port: u16,
|
|
|
|
pub database_url: String,
|
|
|
|
pub cache_url: String,
|
|
|
|
}
|
|
|
|
|
2024-02-25 16:26:39 +00:00
|
|
|
#[derive(Deserialize, Debug, Clone)]
|
2023-12-11 15:18:43 +00:00
|
|
|
pub struct SiteCfg {
|
|
|
|
pub name: String,
|
|
|
|
pub description: String,
|
2024-03-03 20:02:17 +00:00
|
|
|
pub theme: String,
|
|
|
|
pub links: Vec<Vec<(String, String)>>,
|
|
|
|
pub noko: bool,
|
2023-12-11 15:18:43 +00:00
|
|
|
}
|
|
|
|
|
2024-02-25 16:26:39 +00:00
|
|
|
#[derive(Deserialize, Debug, Clone)]
|
2023-12-11 15:18:43 +00:00
|
|
|
pub struct SecretsCfg {
|
|
|
|
pub auth_token: String,
|
|
|
|
pub secure_trip: String,
|
|
|
|
pub user_id: String,
|
|
|
|
}
|
|
|
|
|
2024-02-25 16:26:39 +00:00
|
|
|
#[derive(Deserialize, Debug, Clone)]
|
2023-12-11 15:18:43 +00:00
|
|
|
pub struct FilesCfg {
|
|
|
|
pub videos: bool,
|
|
|
|
pub thumb_size: u32,
|
|
|
|
pub max_size_mb: usize,
|
|
|
|
pub max_height: u32,
|
|
|
|
pub max_width: u32,
|
|
|
|
pub cleanup_interval: u64,
|
|
|
|
}
|
|
|
|
|
2024-02-25 16:26:39 +00:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
2023-12-11 15:18:43 +00:00
|
|
|
pub struct BoardCfg {
|
|
|
|
pub anon_name: String,
|
|
|
|
pub page_size: i64,
|
|
|
|
pub page_count: i64,
|
|
|
|
pub file_limit: usize,
|
|
|
|
pub bump_limit: i32,
|
|
|
|
pub reply_limit: i32,
|
|
|
|
pub locked: bool,
|
|
|
|
pub user_ids: bool,
|
|
|
|
pub flags: bool,
|
|
|
|
pub thread_captcha: String,
|
|
|
|
pub reply_captcha: String,
|
2024-02-17 21:24:39 +00:00
|
|
|
pub board_theme: String,
|
2023-12-11 15:18:43 +00:00
|
|
|
pub require_thread_content: bool,
|
|
|
|
pub require_thread_file: bool,
|
|
|
|
pub require_reply_content: bool,
|
|
|
|
pub require_reply_file: bool,
|
2023-12-13 15:17:49 +00:00
|
|
|
pub antispam: bool,
|
|
|
|
pub antispam_ip: i64,
|
|
|
|
pub antispam_content: i64,
|
|
|
|
pub antispam_both: i64,
|
2024-03-03 20:02:17 +00:00
|
|
|
pub thread_cooldown: i64,
|
2023-12-11 15:18:43 +00:00
|
|
|
}
|