Files
nexus/crates/nexus-api/src/state.rs
wlkns-dev 993172d03e feat(ui): Benutzer mit Rollen, Anmeldung mit Passwort, erste Einrichtung (#1062)
Argon2id, Standard-Admin mit Einmalpasswort in Datei, eigener Admin bei der
ersten Einrichtung, Rollen admin und nutzer, Benutzerverwaltung, Mein Konto,
nexus user. Die Anmeldung mit API-Key an der Oberfläche entfällt.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GmHhg3osejhFSpUz472iQ1
2026-11-16 13:59:01 +01:00

47 lines
1.5 KiB
Rust

use std::collections::HashMap;
use std::sync::{Arc, Mutex, MutexGuard};
use std::time::Instant;
use nexus_store::Store;
use crate::runtime::Runtime;
use crate::ui::Session;
/// Gemeinsamer Zustand aller Anfragen.
pub struct AppState {
store: Arc<Mutex<Store>>,
pub runtime: Runtime,
pub http: reqwest::Client,
/// Start des Gateways (für die Laufzeit in der Übersicht).
pub started: Instant,
/// Sitzungen der Weboberfläche (nur im Speicher; ein Neustart meldet ab).
pub sessions: Mutex<HashMap<String, Session>>,
/// Datei mit dem Einmalpasswort des Standard-Admins; sie wird nach der
/// ersten Einrichtung gelöscht.
pub bootstrap_file: std::sync::OnceLock<std::path::PathBuf>,
}
impl AppState {
pub fn new(store: Store, runtime: Runtime) -> Arc<Self> {
let http = reqwest::Client::builder()
.connect_timeout(std::time::Duration::from_secs(5))
.build()
.expect("HTTP-Client konnte nicht gebaut werden");
let store = Arc::new(Mutex::new(store));
runtime.attach_store(store.clone());
Arc::new(Self {
store,
runtime,
http,
started: Instant::now(),
sessions: Mutex::new(HashMap::new()),
bootstrap_file: std::sync::OnceLock::new(),
})
}
/// Zugriff auf die Datenbank. Nie über ein `await` hinweg halten.
pub fn store(&self) -> MutexGuard<'_, Store> {
self.store.lock().unwrap_or_else(|e| e.into_inner())
}
}