Files
dbx/crates/dbx-web/src/state.rs
T

31 lines
976 B
Rust

use dbx_core::connection::AppState;
use std::collections::{HashMap, HashSet};
use std::path::PathBuf;
use std::sync::Arc;
use tokio::sync::{broadcast, Mutex, RwLock};
use tokio_util::sync::CancellationToken;
pub struct LoginRateLimit {
pub fail_count: u32,
pub locked_until: Option<std::time::Instant>,
}
pub struct WebState {
pub app: Arc<AppState>,
pub data_dir: PathBuf,
pub password_disabled: bool,
pub password_hash: RwLock<Option<String>>,
pub sessions: RwLock<HashSet<String>>,
pub sse_channels: RwLock<HashMap<String, broadcast::Sender<String>>>,
pub sql_file_executions: RwLock<HashMap<String, CancellationToken>>,
pub login_rate_limit: Mutex<LoginRateLimit>,
/// Table export temp files: export_id -> (file_path, format)
pub export_files: RwLock<HashMap<String, (String, String)>>,
}
impl WebState {
pub async fn remove_sse_channel(&self, id: &str) {
self.sse_channels.write().await.remove(id);
}
}