Compare commits

...

2 Commits

Author SHA1 Message Date
Aiirondev_dev 8251cd9bfd Fix of a dubled function 2026-07-29 00:22:35 +02:00
Aiirondev_dev 3ed3148b8a Fix of the notifikationssystem 2026-07-29 00:10:12 +02:00
2 changed files with 24 additions and 33 deletions
+17 -30
View File
@@ -10375,11 +10375,24 @@ def my_borrowed_items():
@app.route('/api/push/vapid-key', methods=['GET'])
def get_vapid_key():
"""Returns the VAPID public key for web push subscriptions."""
"""
Returns the VAPID public key for web push subscriptions
"""
from Web.push_notifications import _get_vapid_public
if not _get_vapid_public():
return jsonify({'error': 'VAPID public key not configured'}), 500
return jsonify({'publicKey': _get_vapid_public()})
if 'username' not in session:
return jsonify({'success': False, 'error': 'Not authenticated'}), 401
try:
if not _get_vapid_public():
return jsonify({'success': False, 'error': 'VAPID public key not configured'}), 500
return jsonify({
'success': True,
'publicKey': _get_vapid_public()
})
except Exception as e:
app.logger.error(f'Error getting VAPID key: {e}')
return jsonify({'success': False}), 500
@app.route('/notifications')
def notifications_view():
@@ -12225,32 +12238,6 @@ def get_push_subscriptions():
app.logger.error(f'Error getting push subscriptions: {e}')
return jsonify({'success': False}), 500
@app.route('/api/push/vapid-key', methods=['GET'])
def get_vapid_key():
"""
Get the VAPID public key for push notifications
Used by the service worker to communicate with push service
"""
try:
vapid_key = pn.VAPID_PUBLIC_KEY
if not vapid_key:
app.logger.warning('VAPID_PUBLIC_KEY not configured')
return jsonify({
'success': False,
'error': 'Push notifications not configured on server'
}), 501
return jsonify({
'success': True,
'vapid_key': vapid_key
})
except Exception as e:
app.logger.error(f'Error getting VAPID key: {e}')
return jsonify({'success': False}), 500
@app.route('/api/push/test', methods=['POST'])
def test_push_notification():
"""
+7 -3
View File
@@ -40,14 +40,18 @@ try:
else:
vapid = Vapid.from_file(VAPID_PRIVATE_PEM)
# Extract public key in standard uncompressed point format encoded in URL-safe base64
raw_pub = vapid.public_key.public_bytes(
serialization.Encoding.X962,
serialization.PublicFormat.UncompressedPoint
)
VAPID_PUBLIC_KEY = b64urlencode(raw_pub).decode('utf-8')
VAPID_PRIVATE_KEY = VAPID_PRIVATE_PEM # pywebpush accepts the file path to the private PEM
encoded_pub = b64urlencode(raw_pub)
if isinstance(encoded_pub, bytes):
VAPID_PUBLIC_KEY = encoded_pub.decode('utf-8')
else:
VAPID_PUBLIC_KEY = encoded_pub
VAPID_PRIVATE_KEY = VAPID_PRIVATE_PEM
except Exception as e:
logger.error(f'Could not load or generate VAPID keys: {e}')