PowerTools/backend/community_settings_srv/src/main.rs

59 lines
1.8 KiB
Rust
Raw Normal View History

2023-12-22 21:26:50 +00:00
mod api;
mod cli;
mod consts;
2023-12-22 21:26:50 +00:00
mod file_util;
mod upgrade;
2023-12-22 21:26:50 +00:00
use actix_web::{web, App, HttpServer};
#[tokio::main]
async fn main() -> std::io::Result<()> {
let args = cli::Cli::get();
println!("cli: {:?}", args);
simplelog::WriteLogger::init(
#[cfg(debug_assertions)]
{
log::LevelFilter::Debug
},
#[cfg(not(debug_assertions))]
{
log::LevelFilter::Info
},
Default::default(),
std::fs::File::create(&args.log).expect("Failed to create log file"),
//std::fs::File::create("/home/deck/powertools-rs.log").unwrap(),
)
.unwrap();
log::debug!("Logging to: {}", args.log.display());
// setup
log::debug!("Building folder layout (if not exists) at: {}", &args.folder.display());
upgrade::build_folder_layout(&args.folder)?;
2024-04-12 22:31:48 +01:00
// fix things
if args.fix {
2024-04-13 02:55:29 +01:00
log::info!("Fixing old symlinks");
upgrade::fix_symlinks(&args.folder)?;
log::info!("Creating missing by_tag folders");
upgrade::make_tag_subfolders(&args.folder)?;
2024-04-13 02:55:29 +01:00
log::info!("Resynchronizing file IDs with file name IDs");
upgrade::sync_ids(&args.folder)?;
2024-04-12 22:31:48 +01:00
return Ok(())
}
2023-12-22 21:26:50 +00:00
let leaked_args: &'static cli::Cli = Box::leak::<'static>(Box::new(args));
HttpServer::new(move || {
App::new()
.app_data(web::Data::new(leaked_args))
//.app_data(web::Data::new(IndexPage::load("dist/index.html").unwrap()))
//.app_data(basic::Config::default().realm("Restricted area"))
.service(api::get_setting_by_id)
.service(api::get_setting_by_steam_app_id)
2023-12-22 21:26:50 +00:00
.service(api::save_setting_with_new_id)
})
.bind(("0.0.0.0", leaked_args.port))?
.run()
.await
}