1
0
mirror of https://git.ngram.ca/OpenJam/rc-servers synced 2026-08-23 23:08:52 +00:00

Replace rc_static_data with general CDN implementation

This commit is contained in:
NG (Graham)
2025-05-24 13:42:53 -04:00
parent 4f0bcde7d8
commit e7de53929d
16 changed files with 553 additions and 141 deletions

27
cdn/src/cli.rs Normal file
View File

@@ -0,0 +1,27 @@
use clap::Parser;
#[derive(Parser, Debug, Clone)]
#[command(version, about, long_about = None)]
pub struct CliArgs {
/// TCP port on which to accept connections
#[arg(short, long, default_value_t = 8010)]
pub port: u16,
/// IP Address on which to accept connections
#[arg(long, default_value_t = {"127.0.0.1".to_string()})]
pub ip: String,
/// Assets root
#[arg(long, default_value_t = {"../assets/robocraft".to_string()})]
pub assets_robocraft: String,
/// User data root
#[arg(long, default_value_t = {"../data/robocraft".to_string()})]
pub data_robocraft: String,
}
impl CliArgs {
pub fn get() -> Self {
Self::parse()
}
}

29
cdn/src/main.rs Normal file
View File

@@ -0,0 +1,29 @@
mod cli;
mod robocraft;
use actix_web::{App, HttpServer, Responder};
#[actix_web::get("/")]
async fn index() -> impl Responder {
let name = env!("CARGO_PKG_NAME");
let version = env!("CARGO_PKG_VERSION");
let authors = env!("CARGO_PKG_AUTHORS");
let license = env!("CARGO_PKG_LICENSE");
let repo = env!("CARGO_PKG_REPOSITORY");
format!("{} {} by [{}]\n{}\n{}", name, version, authors, license, repo)
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let cli_args = cli::CliArgs::get();
let cli_args2 = cli_args.clone();
HttpServer::new(move || {
App::new()
.app_data(actix_web::web::Data::new(cli_args2.clone()))
.service(index)
.service(robocraft::live_data::live_data_json)
})
.bind((cli_args.ip, cli_args.port))?
.run()
.await
}

View File

@@ -0,0 +1,7 @@
use actix_web::{get, Responder, web::Data};
#[get("/live/data.json")]
pub async fn live_data_json(cli: Data<crate::cli::CliArgs>) -> impl Responder {
let path = std::path::PathBuf::from(&cli.assets_robocraft).join("live_data.json");
actix_files::NamedFile::open_async(path).await
}

1
cdn/src/robocraft/mod.rs Normal file
View File

@@ -0,0 +1 @@
pub mod live_data;