use std::io; use actix_web::{App, HttpServer, web}; pub mod caches; pub mod services; pub struct AppState { pub args: crate::args::Args, pub config: &'static crate::conf::Config, pub cache: caches::AppCache<'static>, } /// Leaks memory for the sake of not atomic'ing all over. #[expect(clippy::missing_errors_doc)] pub async fn start_app(args: crate::args::Args, config: crate::conf::Config) -> io::Result<()> { use crate::consts::web_scopes as ws; let config = Box::leak(Box::new(config)); let cache = caches::AppCache::new( config.unix.magic_paths.clone(), // ["/usr/share/file/misc/magic"] // .try_into() // .expect("To be valid DB paths"), &config.unix.groups, ); let app: &AppState = Box::leak(Box::new(AppState { args, config, cache, })); println!( "\x1b[32mINF\x1b[0m: Trying to listen on {:?}", app.config.server.listen ); HttpServer::new(move || { App::new() .app_data(web::Data::new(app)) .service(services::images::make_scope(ws::IMAGES)) }) .bind(&app.config.server.listen)? .run() .await }