63 lines
1.9 KiB
Rust
63 lines
1.9 KiB
Rust
mod api;
|
|
mod cli;
|
|
mod consts;
|
|
mod file_util;
|
|
mod tasks;
|
|
mod upgrade;
|
|
|
|
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)?;
|
|
|
|
// fix things
|
|
if args.fix {
|
|
log::info!("Fixing old symlinks");
|
|
upgrade::fix_symlinks(&args.folder)?;
|
|
log::info!("Creating missing by_tag folders");
|
|
upgrade::make_tag_subfolders(&args.folder)?;
|
|
log::info!("Resynchronizing file IDs with file name IDs");
|
|
upgrade::sync_ids(&args.folder)?;
|
|
log::info!("Rebuilding missing symlinks");
|
|
upgrade::rebuild_symlinks(&args.folder)?;
|
|
return Ok(())
|
|
}
|
|
|
|
tasks::start_tasks(args.clone());
|
|
|
|
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)
|
|
.service(api::save_setting_with_new_id)
|
|
})
|
|
.bind(("0.0.0.0", leaked_args.port))?
|
|
.run()
|
|
.await
|
|
}
|