2022-12-10 02:10:14 +00:00
|
|
|
mod cli;
|
2022-12-08 02:30:10 +00:00
|
|
|
mod consts;
|
|
|
|
mod not_decky;
|
2022-12-10 02:10:14 +00:00
|
|
|
mod storage;
|
2022-12-08 02:30:10 +00:00
|
|
|
|
2022-12-10 02:10:14 +00:00
|
|
|
use actix_web::{get, web, App, HttpResponse, HttpServer, Responder};
|
|
|
|
use simplelog::{LevelFilter, WriteLogger};
|
2022-12-08 02:30:10 +00:00
|
|
|
|
2024-05-11 05:18:42 +01:00
|
|
|
static ARGS: std::sync::OnceLock<cli::CliArgs> = std::sync::OnceLock::new();
|
|
|
|
|
2022-12-08 02:30:10 +00:00
|
|
|
#[get("/version_info")]
|
|
|
|
async fn hello() -> impl Responder {
|
2024-05-11 05:18:42 +01:00
|
|
|
let args = ARGS.get_or_init(|| cli::CliArgs::get());
|
|
|
|
HttpResponse::Ok().body(format!("{} v{} {}", consts::PACKAGE_NAME, consts::PACKAGE_VERSION, args.storage.clone().to_descriptor()))
|
2022-12-08 02:30:10 +00:00
|
|
|
}
|
|
|
|
|
2022-12-17 05:03:41 +00:00
|
|
|
fn build_storage_box(storage: &cli::StorageArgs) -> Box<dyn storage::IStorage> {
|
2023-07-01 00:21:24 +01:00
|
|
|
log::debug!("storage args {:?}", storage);
|
2022-12-17 05:03:41 +00:00
|
|
|
match storage {
|
|
|
|
cli::StorageArgs::Default => Box::new(storage::FileStorage::new(
|
|
|
|
"./store".into(),
|
|
|
|
"http://192.168.0.128:22252".into(),
|
|
|
|
true,
|
|
|
|
)),
|
|
|
|
cli::StorageArgs::Filesystem(fs) => Box::new(storage::FileStorage::new(
|
|
|
|
fs.root.clone().into(),
|
|
|
|
fs.domain_root.clone().into(),
|
|
|
|
fs.enable_stats,
|
|
|
|
)),
|
|
|
|
cli::StorageArgs::Proxy(px) => Box::new(storage::ProxiedStorage::new(
|
|
|
|
px.proxy_store.clone(),
|
2024-05-11 03:10:53 +01:00
|
|
|
px.intercept_artifacts,
|
|
|
|
px.intercept_images,
|
|
|
|
px.domain_root.clone(),
|
2022-12-17 05:03:41 +00:00
|
|
|
)),
|
|
|
|
cli::StorageArgs::Empty => Box::new(storage::EmptyStorage),
|
|
|
|
cli::StorageArgs::Merge(ls) => Box::new(storage::MergedStorage::new(
|
|
|
|
ls.generate_args()
|
|
|
|
.expect("Bad descriptor")
|
|
|
|
.drain(..)
|
|
|
|
.map(|args| build_storage_box(&args))
|
|
|
|
.collect()
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-08 02:30:10 +00:00
|
|
|
#[actix_web::main]
|
|
|
|
async fn main() -> std::io::Result<()> {
|
2024-05-11 05:18:42 +01:00
|
|
|
let args = ARGS.get_or_init(|| cli::CliArgs::get());
|
2022-12-10 02:10:14 +00:00
|
|
|
let log_filepath = std::path::Path::new("/tmp").join(format!("{}.log", consts::PACKAGE_NAME));
|
2023-12-31 02:44:10 +00:00
|
|
|
#[cfg(debug_assertions)]
|
|
|
|
let log_level = LevelFilter::Debug;
|
|
|
|
#[cfg(not(debug_assertions))]
|
|
|
|
let log_level = LevelFilter::Info;
|
2022-12-10 02:10:14 +00:00
|
|
|
WriteLogger::init(
|
2023-12-31 02:44:10 +00:00
|
|
|
log_level,
|
2022-12-10 02:10:14 +00:00
|
|
|
Default::default(),
|
|
|
|
std::fs::File::create(&log_filepath).unwrap(),
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
println!("Logging to {}", log_filepath.display());
|
|
|
|
|
|
|
|
HttpServer::new(move || {
|
2022-12-08 02:30:10 +00:00
|
|
|
let cors = actix_cors::Cors::default()
|
2022-12-10 02:41:39 +00:00
|
|
|
//.allowed_origin("https://steamloopback.host")
|
|
|
|
.allow_any_origin()
|
|
|
|
.send_wildcard()
|
|
|
|
.allow_any_method()
|
2022-12-08 02:30:10 +00:00
|
|
|
.allow_any_header()
|
|
|
|
.expose_any_header();
|
|
|
|
|
2022-12-17 05:03:41 +00:00
|
|
|
let storage_data: Box<dyn storage::IStorage> = build_storage_box(&args.storage);
|
|
|
|
|
|
|
|
let storage_data = if let Some(cache_duration) = args.cache_duration {
|
|
|
|
Box::new(storage::CachedStorage::new(cache_duration, storage_data))
|
|
|
|
} else {
|
|
|
|
storage_data
|
2022-12-10 02:10:14 +00:00
|
|
|
};
|
|
|
|
|
2022-12-08 02:30:10 +00:00
|
|
|
App::new()
|
|
|
|
.wrap(cors)
|
2022-12-10 02:10:14 +00:00
|
|
|
.app_data(web::Data::new(storage_data))
|
2022-12-08 02:30:10 +00:00
|
|
|
.service(hello)
|
|
|
|
.service(not_decky::decky_index)
|
|
|
|
.service(not_decky::decky_plugins)
|
2022-12-10 02:10:14 +00:00
|
|
|
.service(not_decky::decky_artifact)
|
|
|
|
.service(not_decky::decky_image)
|
|
|
|
.service(not_decky::decky_statistics)
|
2023-12-31 03:41:51 +00:00
|
|
|
.service(not_decky::decky_statistics_increment)
|
2022-12-08 02:30:10 +00:00
|
|
|
})
|
2023-07-01 00:21:24 +01:00
|
|
|
.bind(("0.0.0.0", args.server_port.unwrap_or(22252)))?
|
2022-12-08 02:30:10 +00:00
|
|
|
.run()
|
|
|
|
.await
|
2022-12-07 22:07:25 +00:00
|
|
|
}
|