nekrochan/src/cfg.rs

80 řádky
1.8 KiB
Rust
Surový Normální zobrazení Historie

2024-03-16 11:16:46 +00:00
use anyhow::Error;
use serde::{Deserialize, Serialize};
use tokio::fs::read_to_string;
#[derive(Deserialize, Debug, Clone)]
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)
}
}
#[derive(Deserialize, Debug, Clone)]
pub struct ServerCfg {
pub port: u16,
pub database_url: String,
pub cache_url: String,
}
#[derive(Deserialize, Debug, Clone)]
pub struct SiteCfg {
pub name: String,
pub description: String,
pub theme: String,
pub links: Vec<Vec<(String, String)>>,
pub noko: bool,
}
#[derive(Deserialize, Debug, Clone)]
pub struct SecretsCfg {
pub auth_token: String,
pub secure_trip: String,
pub user_id: String,
}
#[derive(Deserialize, Debug, Clone)]
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,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
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,
pub board_theme: String,
pub require_thread_content: bool,
pub require_thread_file: bool,
pub require_reply_content: bool,
pub require_reply_file: bool,
pub antispam: bool,
pub antispam_ip: i64,
pub antispam_content: i64,
pub antispam_both: i64,
pub thread_cooldown: i64,
}