mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Add API endpoint for retrieving config.json (without any secure access details)
This commit is contained in:
28
rc_society/src/api/config.rs
Normal file
28
rc_society/src/api/config.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
use actix_web::{HttpResponse, Responder, get, web::Query, http::header::{ContentDisposition, ContentType}};
|
||||
|
||||
static JSON_DATA: std::sync::OnceLock<String> = std::sync::OnceLock::new();
|
||||
|
||||
pub(super) fn init(config: &dyn oj_rc_core::ConfigProvider<()>) {
|
||||
JSON_DATA.get_or_init(|| config.redacted_json());
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
struct ConfigQuery {
|
||||
#[serde(default)]
|
||||
pub download: bool,
|
||||
}
|
||||
|
||||
#[get("/api/v1/config.json")]
|
||||
pub async fn get(query: Query<ConfigQuery>) -> impl Responder {
|
||||
let data = JSON_DATA.get().expect("Config JSON init failure").to_owned();
|
||||
if query.download {
|
||||
HttpResponse::Ok()
|
||||
.insert_header(ContentDisposition::attachment("config.json"))
|
||||
.insert_header(ContentType::json())
|
||||
.body(data)
|
||||
} else {
|
||||
HttpResponse::Ok()
|
||||
.insert_header(ContentType::json())
|
||||
.body(data)
|
||||
}
|
||||
}
|
||||
@@ -1 +1,6 @@
|
||||
pub mod garage;
|
||||
pub mod config;
|
||||
|
||||
pub fn init(config: &dyn oj_rc_core::ConfigProvider<()>) {
|
||||
config::init(config);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ async fn main() -> std::io::Result<()> {
|
||||
let cli_args = cli::CliArgs::get();
|
||||
|
||||
let config = oj_rc_core::ConfigImpl::load(&cli_args.assets_robocraft)?;
|
||||
api::init(&config);
|
||||
|
||||
let server_settings = actix_web::web::Data::new(<oj_rc_core::ConfigImpl as oj_rc_core::ConfigProvider<()>>::server_config(&config));
|
||||
let server_links = actix_web::web::Data::new(<oj_rc_core::ConfigImpl as oj_rc_core::ConfigProvider<()>>::url_links(&config));
|
||||
@@ -94,6 +95,7 @@ async fn main() -> std::io::Result<()> {
|
||||
.service(web::garage::import::get_new)
|
||||
.service(web::garage::import::post)
|
||||
.service(web::garage::selected::get)
|
||||
.service(api::config::get)
|
||||
})
|
||||
.bind((cli_args.ip, cli_args.port))?
|
||||
.run()
|
||||
|
||||
Reference in New Issue
Block a user