diff options
Diffstat (limited to 'src/push/handlers/mod.rs')
| -rw-r--r-- | src/push/handlers/mod.rs | 26 |
1 files changed, 6 insertions, 20 deletions
diff --git a/src/push/handlers/mod.rs b/src/push/handlers/mod.rs index afa76e0..89e0743 100644 --- a/src/push/handlers/mod.rs +++ b/src/push/handlers/mod.rs @@ -32,35 +32,22 @@ pub async fn unregister() -> String { #[axum::debug_handler] pub async fn echo( - Json(echo): Json<Echo>, + Json(payload): Json<PushPayload>, ) -> Result<(), crate::error::Internal> { - // Look this up from a subscription record? Or get it from the client and trust? - let endpoint = echo.endpoint; - // Get these from client: - let p256dh = echo.keys.p256dh; - let auth = echo.keys.auth; - - println!("endpoint: {:?}", endpoint); - println!("p256dh: {:?}", p256dh); - println!("auth: {:?}", auth); - - // You would likely get this by deserializing a browser `pushSubscription` object. + let endpoint = payload.endpoint; + let p256dh = payload.keys.p256dh; + let auth = payload.keys.auth; let subscription_info = SubscriptionInfo::new(endpoint, p256dh, auth); // This will need to come from the DB eventually. let private_key = String::from(env::var("VAPID_PRIVATE_KEY").unwrap_or_default()); let sig_builder = VapidSignatureBuilder::from_base64(&private_key, &subscription_info)?.build()?; - - // Now add payload and encrypt. let mut builder = WebPushMessageBuilder::new(&subscription_info); // Eventually, this message will be something other than an echo: - let content = echo.msg.as_bytes(); + let content = payload.msg.as_bytes(); builder.set_payload(ContentEncoding::Aes128Gcm, content); builder.set_vapid_signature(sig_builder); - let client = IsahcWebPushClient::new()?; - - // Finally, send the notification! client.send(builder.build()?).await?; // Fix up return type? Ok(()) @@ -74,9 +61,8 @@ pub struct Keys { } #[derive(serde::Deserialize)] -pub struct Echo { +pub struct PushPayload { pub msg: String, pub endpoint: String, - pub expirationTime: Option<String>, pub keys: Keys, } |
