feat: add image fetching
This commit is contained in:
47
src/server/mod.rs
Normal file
47
src/server/mod.rs
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user