test notification

This commit is contained in:
Karl 2025-07-17 19:05:59 +01:00
parent 07dc830160
commit cf46844a4e
2 changed files with 29 additions and 1 deletions

19
app.py
View File

@ -120,6 +120,25 @@ def proxy_save_subscription():
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
return jsonify({"error": str(e)}), 502 return jsonify({"error": str(e)}), 502
@app.route('/send-test-notification', methods=['POST'])
def proxy_send_test_notification():
"""Proxies the request to send a test notification to the backend."""
if not session.get("logged_in"):
return jsonify({'error': 'Unauthorized'}), 401
backend_url = f"{app.config['BASE_URL']}/send-test-notification"
credentials = base64.b64decode(session["auth_credentials"]).decode()
username, password = credentials.split(":", 1)
try:
response = requests.post(
backend_url,
auth=requests.auth.HTTPBasicAuth(username, password)
)
return Response(response.content, status=response.status_code, mimetype=response.headers['Content-Type'])
except requests.exceptions.RequestException as e:
return jsonify({"error": str(e)}), 502
@app.route("/home") @app.route("/home")
@cache.cached(timeout=60) @cache.cached(timeout=60)
def home() -> str: def home() -> str:

View File

@ -46,7 +46,7 @@
</main> </main>
<footer class="bg-dark text-white text-center py-3 mt-5"> <footer class="bg-dark text-white text-center py-3 mt-5">
<p>Version: {{ version }}</p> <p>Version: <a href="#" id="version-link">{{ version }}</a></p>
</footer> </footer>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
@ -65,6 +65,15 @@
}, function(err) { }, function(err) {
console.log('ServiceWorker registration failed: ', err); console.log('ServiceWorker registration failed: ', err);
}); });
document.getElementById('version-link').addEventListener('click', function(event) {
event.preventDefault();
fetch('/send-test-notification', {
method: 'POST'
}).then(response => response.json())
.then(data => console.log(data.message))
.catch(err => console.error('Error sending test notification:', err));
});
} }
function askPermission(registration) { function askPermission(registration) {