From af85b971b1e32bfef919a72910664f45c8c6dfc8 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Sat, 23 Dec 2023 17:58:26 -0700 Subject: [PATCH] fix some things that are wrong in the data structures --- app.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index cc6fc1b..a8eab28 100644 --- a/app.py +++ b/app.py @@ -434,8 +434,8 @@ class WebPushService(): # Retrieving the subscription information from the incoming request content = request.json endpoint = content['endpoint'] - p256dh = content['p256dh'] - auth = content['auth'] + p256dh = content['keys']['p256dh'] + auth = content['keys']['auth'] # Looking up the subscription in the database subscription = Subscription.query.filter_by(endpoint=endpoint, p256dh=p256dh, auth=auth).first() @@ -449,10 +449,11 @@ class WebPushService(): "auth": subscription.auth } } - vapid_key = VAPIDKey.query.first() - result = WebPushService._send_push_notification(subscription_info, {"title": "Test Notification", "message": "This is a test notification"}, vapid_key) + vapid_key = VAPIDKey.query.filter_by(id = subscription.vapid_key_id) + result = WebPushService._send_push_notification(subscription_info, {"title": "Test Notification", "message": "This is a test notification"}, vapid_key.private_key) return jsonify(result) else: return jsonify({"success": False, "message": "Subscription not found"}), 404 + web_push_service = WebPushService(app, "app")