1
0
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:
NG (Graham)
2026-06-21 21:58:36 -04:00
parent c4f297eb18
commit e60a4927a6
8 changed files with 102 additions and 0 deletions

View 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)
}
}

View File

@@ -1 +1,6 @@
pub mod garage;
pub mod config;
pub fn init(config: &dyn oj_rc_core::ConfigProvider<()>) {
config::init(config);
}