2025-12-17 10:38:37 -07:00
|
|
|
use std::{error::Error, path::PathBuf};
|
|
|
|
|
|
2025-12-17 13:17:58 -07:00
|
|
|
mod blobs;
|
2025-12-03 10:15:20 -07:00
|
|
|
mod database;
|
|
|
|
|
mod manager;
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
pub struct Server {
|
2025-12-17 10:38:37 -07:00
|
|
|
pub component_configs: Vec<crate::config::ComponentState>,
|
2025-12-17 10:20:50 -07:00
|
|
|
// pub manager: Arc<Mutex<Manager>>,
|
2025-12-03 10:15:20 -07:00
|
|
|
pub db: sled::Db,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Server {
|
2025-12-17 10:38:37 -07:00
|
|
|
pub fn new(config_paths: Vec<PathBuf>, database: String) -> Result<Self, Box<dyn Error>> {
|
|
|
|
|
let mut component_configs: Vec<crate::config::ComponentState> = Vec::new();
|
|
|
|
|
|
|
|
|
|
for config in &config_paths {
|
|
|
|
|
component_configs.extend(crate::config::load_config(config)?);
|
2025-12-03 10:15:20 -07:00
|
|
|
}
|
2025-12-17 10:38:37 -07:00
|
|
|
|
|
|
|
|
Ok(Self {
|
|
|
|
|
component_configs,
|
|
|
|
|
// manager: Manager::start(&SERVER_CONFIG, Vec::new()),
|
|
|
|
|
db: sled::open(database)?,
|
|
|
|
|
})
|
2025-12-03 10:15:20 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Drop for Server {
|
|
|
|
|
fn drop(&mut self) {
|
|
|
|
|
self.db.flush().expect("Failed to flush database on drop");
|
2025-12-17 10:20:50 -07:00
|
|
|
// Manager::join(self.manager.clone());
|
2025-12-03 10:15:20 -07:00
|
|
|
}
|
|
|
|
|
}
|