|
|
@ -29,18 +29,21 @@ def create_app(config_name): |
|
|
|
) |
|
|
|
public_key_base64 = base64.b64encode(public_key_bytes).decode() |
|
|
|
|
|
|
|
private_key_hex = binascii.hexlify(private_key.private_bytes( |
|
|
|
private_key_bytes = private_key.private_bytes( |
|
|
|
encoding=serialization.Encoding.DER, |
|
|
|
format=serialization.PrivateFormat.PKCS8, |
|
|
|
encryption_algorithm=serialization.NoEncryption() |
|
|
|
)).decode() |
|
|
|
) |
|
|
|
|
|
|
|
private_key_base64 = base64.b64encode(private_key_bytes).decode() |
|
|
|
|
|
|
|
key = VAPIDKey(public_key=public_key_base64, private_key=private_key_base64) |
|
|
|
db.session.add(key) |
|
|
|
db.session.commit() |
|
|
|
|
|
|
|
except Exception as e: |
|
|
|
print(f"Error generating VAPID keys: {e}") |
|
|
|
|
|
|
|
key = VAPIDKey(public_key=public_key_base64, private_key=private_key_hex) |
|
|
|
db.session.add(key) |
|
|
|
db.session.commit() |
|
|
|
|
|
|
|
|
|
|
|
def initialize(): |
|
|
@ -51,17 +54,14 @@ def create_app(config_name): |
|
|
|
def send_push_notification(subscription_info, message, vapid_key): |
|
|
|
result = True |
|
|
|
try: |
|
|
|
private_key_hex = vapid_key.private_key |
|
|
|
private_key_der = bytes.fromhex(private_key_hex) |
|
|
|
|
|
|
|
private_key_base64 = base64.b64encode(private_key_der).decode() |
|
|
|
private_key_base64 = vapid_key.private_key |
|
|
|
|
|
|
|
webpush( |
|
|
|
subscription_info=subscription_info, |
|
|
|
data=json.dumps(message), |
|
|
|
vapid_private_key=private_key_base64, |
|
|
|
vapid_claims={ |
|
|
|
"sub": "mailto:matthew.raymer@gmail.com" |
|
|
|
"sub": "mailto:info@timesafari.org" |
|
|
|
} |
|
|
|
) |
|
|
|
|
|
|
|