Add endpoint for client to fetch current date
This commit is contained in:
parent
20f5da98e3
commit
4f67f033c7
|
@ -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<Body> {
|
||||
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<Body> {
|
||||
let req = match serde_json::from_slice(&request) {
|
||||
Ok(req) => req,
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue