feat: add image fetching

This commit is contained in:
2026-03-20 19:48:18 +01:00
parent fb62111c7f
commit 12388a9908
17 changed files with 2122 additions and 92 deletions

47
src/server/mod.rs Normal file
View File

@@ -0,0 +1,47 @@
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<()> {
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::get_image)
// .service(factory)
})
.bind(&app.config.server.listen)?
.run()
.await
}