Compare commits
No commits in common. "6b30769d968dd0ca24ed1393304a83c0cbddb532" and "c9329a33ea2a901b5cc45d2f82d53f4b9c7dc991" have entirely different histories.
6b30769d96
...
c9329a33ea
@ -1,5 +1,5 @@
|
|||||||
[tool.bumpversion]
|
[tool.bumpversion]
|
||||||
current_version = "1.3.28"
|
current_version = "1.3.27"
|
||||||
commit = true
|
commit = true
|
||||||
tag = true
|
tag = true
|
||||||
tag_name = "{new_version}"
|
tag_name = "{new_version}"
|
||||||
|
38
app.py
38
app.py
@ -6,6 +6,7 @@ import requests.auth
|
|||||||
import os
|
import os
|
||||||
import base64
|
import base64
|
||||||
from typing import Dict, Any, Tuple, Union
|
from typing import Dict, Any, Tuple, Union
|
||||||
|
from pywebpush import webpush, WebPushException
|
||||||
|
|
||||||
from lib.datetime import filter_accounts_next_30_days, filter_accounts_expired
|
from lib.datetime import filter_accounts_next_30_days, filter_accounts_expired
|
||||||
from lib.reqs import (get_urls, get_user_accounts, add_user_account,
|
from lib.reqs import (get_urls, get_user_accounts, add_user_account,
|
||||||
@ -90,35 +91,26 @@ def index() -> Union[Response, str]:
|
|||||||
return redirect(url_for("home"))
|
return redirect(url_for("home"))
|
||||||
return render_template("index.html")
|
return render_template("index.html")
|
||||||
|
|
||||||
@app.route('/vapid-public-key', methods=['GET'])
|
@app.route('/vapid-public-key')
|
||||||
def proxy_vapid_public_key():
|
def vapid_public_key():
|
||||||
"""Proxies the request for the VAPID public key to the backend."""
|
"""Provides the VAPID public key to the client."""
|
||||||
backend_url = f"{app.config['BASE_URL']}/vapid-public-key"
|
return jsonify({'public_key': app.config['VAPID_PUBLIC_KEY']})
|
||||||
try:
|
|
||||||
response = requests.get(backend_url)
|
|
||||||
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('/save-subscription', methods=['POST'])
|
@app.route('/save-subscription', methods=['POST'])
|
||||||
def proxy_save_subscription():
|
def save_subscription():
|
||||||
"""Proxies the request to save a push subscription to the backend."""
|
"""Saves a push notification subscription."""
|
||||||
if not session.get("logged_in"):
|
if not session.get("logged_in"):
|
||||||
return jsonify({'error': 'Unauthorized'}), 401
|
return jsonify({'error': 'Unauthorized'}), 401
|
||||||
|
|
||||||
backend_url = f"{app.config['BASE_URL']}/save-subscription"
|
subscription_data = request.get_json()
|
||||||
credentials = base64.b64decode(session["auth_credentials"]).decode()
|
if not subscription_data:
|
||||||
username, password = credentials.split(":", 1)
|
return jsonify({'error': 'No subscription data received'}), 400
|
||||||
|
|
||||||
try:
|
# Here you would typically save the subscription to a database
|
||||||
response = requests.post(
|
# For this example, we'll just store it in the session
|
||||||
backend_url,
|
session['push_subscription'] = subscription_data
|
||||||
auth=requests.auth.HTTPBasicAuth(username, password),
|
print(f"Subscription saved for user: {session['username']}")
|
||||||
json=request.get_json()
|
return jsonify({'success': True})
|
||||||
)
|
|
||||||
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user