diff --git a/crates/lox-distributor/src/lox_context.rs b/crates/lox-distributor/src/lox_context.rs index b732880..2bdad8e 100644 --- a/crates/lox-distributor/src/lox_context.rs +++ b/crates/lox-distributor/src/lox_context.rs @@ -139,6 +139,10 @@ impl LoxServerContext { ] } + fn today(&self) -> u32 { + self.ba.lock().unwrap().today() + } + fn gen_invite(&self) -> lox_utils::Invite { let mut obj = self.db.lock().unwrap(); lox_utils::Invite { @@ -238,6 +242,17 @@ impl LoxServerContext { } } + pub fn send_today(self) -> Response { + let today = self.today(); + match serde_json::to_string(&today) { + Ok(resp) => prepare_header(resp), + Err(e) => { + println!("Error parsing today to JSON"); + prepare_error_header(e.to_string()) + } + } + } + pub fn verify_and_send_open_cred(self, request: Bytes) -> Response { let req = match serde_json::from_slice(&request) { Ok(req) => req, diff --git a/crates/lox-distributor/src/request_handler.rs b/crates/lox-distributor/src/request_handler.rs index c236a52..764c7ab 100644 --- a/crates/lox-distributor/src/request_handler.rs +++ b/crates/lox-distributor/src/request_handler.rs @@ -21,6 +21,7 @@ pub async fn handle( Ok::<_, Infallible>(cloned_context.send_reachability_cred()) } (&Method::POST, "/pubkeys") => Ok::<_, Infallible>(cloned_context.send_keys()), + (&Method::POST, "/today") => Ok::<_, Infallible>(cloned_context.send_today()), (&Method::POST, "/openreq") => Ok::<_, Infallible>({ let bytes = body::to_bytes(req.into_body()).await.unwrap(); cloned_context.verify_and_send_open_cred(bytes)