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 crate::storage::IStorageWrap;
|
|
|
|
|
|
|
|
use actix_web::{get, web, App, HttpResponse, HttpServer, Responder};
|
|
|
|
use simplelog::{LevelFilter, WriteLogger};
|
2022-12-08 02:30:10 +00:00
|
|
|
|
|
|
|
#[get("/version_info")]
|
|
|
|
async fn hello() -> impl Responder {
|
|
|
|
HttpResponse::Ok().body(format!("{} v{}", consts::PACKAGE_NAME, consts::PACKAGE_VERSION))
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_web::main]
|
|
|
|
async fn main() -> std::io::Result<()> {
|
2022-12-10 02:10:14 +00:00
|
|
|
let args = cli::CliArgs::get();
|
|
|
|
let log_filepath = std::path::Path::new("/tmp").join(format!("{}.log", consts::PACKAGE_NAME));
|
|
|
|
WriteLogger::init(
|
|
|
|
LevelFilter::Debug,
|
|
|
|
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()
|
|
|
|
.allowed_origin("https://steamloopback.host")
|
|
|
|
.allow_any_header()
|
|
|
|
.expose_any_header();
|
|
|
|
|
2022-12-10 02:10:14 +00:00
|
|
|
let storage_data: Box<dyn storage::IStorage> = match &args.storage {
|
|
|
|
cli::StorageArgs::Default => storage::FileStorage::new(
|
|
|
|
"./store".into(),
|
|
|
|
"http://192.168.0.128:22252".into(),
|
|
|
|
true,
|
|
|
|
).wrap(args.clone()),
|
|
|
|
cli::StorageArgs::Filesystem(fs) => storage::FileStorage::new(
|
|
|
|
fs.root.clone().into(),
|
|
|
|
fs.domain_root.clone().into(),
|
|
|
|
fs.enable_stats,
|
|
|
|
).wrap(args.clone()),
|
|
|
|
};
|
|
|
|
|
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)
|
2022-12-08 02:30:10 +00:00
|
|
|
})
|
|
|
|
.bind(("0.0.0.0", 22252))?
|
|
|
|
.run()
|
|
|
|
.await
|
2022-12-07 22:07:25 +00:00
|
|
|
}
|