1.2 KiB · text History 63417ef
pub mod actions;
pub mod api;
pub mod auth;
pub mod avatar;
pub mod category_tree;
pub mod config;
pub mod entities;
pub mod handlers;
pub mod mailer;
pub mod markdown;
pub mod seed;
pub mod middleware;
pub mod timeutil;
pub mod trust;

pub use config::{create_db_connection, Config};

use minijinja::Environment;
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use std::time::Instant;
use uuid::Uuid;

/// Per-`(topic, viewer)` last-bump timestamps, used to rate-limit view-count
/// increments so refreshes don't inflate the count. In-memory (resets on
/// restart, not shared across instances) — fine for this single-process app.
pub type ViewThrottle = Arc<Mutex<HashMap<(Uuid, String), Instant>>>;

pub fn new_view_throttle() -> ViewThrottle {
    Arc::new(Mutex::new(HashMap::new()))
}

/// Shared application state handed to every handler via `axum`'s `State`
/// extractor.
#[derive(Clone)]
pub struct AppState {
    pub env: Environment<'static>,
    pub db: Arc<sea_orm::DatabaseConnection>,
    pub config: Arc<Config>,
    pub view_throttle: ViewThrottle,
    /// Outbound mail: mail-prism when configured, else the log.
    pub mailer: Arc<dyn mailer::Mailer>,
}