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:
13
cdn/Cargo.toml
Normal file
13
cdn/Cargo.toml
Normal file
@@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "cdn"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
repository.workspace = true
|
||||
license.workspace = true
|
||||
authors.workspace = true
|
||||
readme.workspace = true
|
||||
|
||||
[dependencies]
|
||||
actix-web.workspace = true
|
||||
actix-files.workspace = true
|
||||
clap.workspace = true
|
||||
3
cdn/build_arm64.sh
Executable file
3
cdn/build_arm64.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
cargo build --release --target aarch64-unknown-linux-musl
|
||||
3
cdn/run_debug.sh
Executable file
3
cdn/run_debug.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
RUST_LOG=debug cargo run
|
||||
27
cdn/src/cli.rs
Normal file
27
cdn/src/cli.rs
Normal 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
29
cdn/src/main.rs
Normal 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
|
||||
}
|
||||
7
cdn/src/robocraft/live_data.rs
Normal file
7
cdn/src/robocraft/live_data.rs
Normal 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
1
cdn/src/robocraft/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod live_data;
|
||||
Reference in New Issue
Block a user