2023-12-22 21:26:50 +00:00
|
|
|
mod api;
|
|
|
|
mod cli;
|
2024-04-20 03:18:06 +01:00
|
|
|
mod consts;
|
2023-12-22 21:26:50 +00:00
|
|
|
mod file_util;
|
2024-04-20 03:18:06 +01:00
|
|
|
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());
|
|
|
|
|
2024-01-06 18:26:35 +00:00
|
|
|
// setup
|
|
|
|
log::debug!("Building folder layout (if not exists) at: {}", &args.folder.display());
|
2024-04-20 03:18:06 +01:00
|
|
|
upgrade::build_folder_layout(&args.folder)?;
|
2024-01-06 18:26:35 +00:00
|
|
|
|
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");
|
2024-04-20 03:18:06 +01:00
|
|
|
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");
|
2024-04-20 03:18:06 +01:00
|
|
|
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)
|
2024-01-06 18:26:35 +00:00
|
|
|
.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
|
|
|
|
}
|