Compare commits
No commits in common. "fbaf79c9ae7848fc81c8d45ecefc2e979c800652" and "1e36958279f50de335e8056ec4123fc7518cd82a" have entirely different histories.
fbaf79c9ae
...
1e36958279
@ -1,5 +1,5 @@
|
|||||||
[tool.bumpversion]
|
[tool.bumpversion]
|
||||||
current_version = "1.3.24"
|
current_version = "1.3.23"
|
||||||
commit = true
|
commit = true
|
||||||
tag = true
|
tag = true
|
||||||
tag_name = "{new_version}"
|
tag_name = "{new_version}"
|
||||||
|
22
app.py
22
app.py
@ -6,7 +6,6 @@ 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,
|
||||||
@ -91,27 +90,6 @@ 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')
|
|
||||||
def vapid_public_key():
|
|
||||||
"""Provides the VAPID public key to the client."""
|
|
||||||
return jsonify({'public_key': app.config['VAPID_PUBLIC_KEY']})
|
|
||||||
|
|
||||||
@app.route('/save-subscription', methods=['POST'])
|
|
||||||
def save_subscription():
|
|
||||||
"""Saves a push notification subscription."""
|
|
||||||
if not session.get("logged_in"):
|
|
||||||
return jsonify({'error': 'Unauthorized'}), 401
|
|
||||||
|
|
||||||
subscription_data = request.get_json()
|
|
||||||
if not subscription_data:
|
|
||||||
return jsonify({'error': 'No subscription data received'}), 400
|
|
||||||
|
|
||||||
# Here you would typically save the subscription to a database
|
|
||||||
# For this example, we'll just store it in the session
|
|
||||||
session['push_subscription'] = subscription_data
|
|
||||||
print(f"Subscription saved for user: {session['username']}")
|
|
||||||
return jsonify({'success': True})
|
|
||||||
|
|
||||||
@app.route("/home")
|
@app.route("/home")
|
||||||
@cache.cached(timeout=60)
|
@cache.cached(timeout=60)
|
||||||
def home() -> str:
|
def home() -> str:
|
||||||
|
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
@ -74,20 +74,16 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function subscribeUser(registration) {
|
function subscribeUser(registration) {
|
||||||
fetch('http://localhost:3001/vapid-public-key')
|
const applicationServerKey = urlB64ToUint8Array('{{ config.VAPID_PUBLIC_KEY }}');
|
||||||
.then(response => response.json())
|
registration.pushManager.subscribe({
|
||||||
.then(data => {
|
userVisibleOnly: true,
|
||||||
const applicationServerKey = urlB64ToUint8Array(data.public_key);
|
applicationServerKey: applicationServerKey
|
||||||
registration.pushManager.subscribe({
|
}).then(function(subscription) {
|
||||||
userVisibleOnly: true,
|
console.log('User is subscribed.');
|
||||||
applicationServerKey: applicationServerKey
|
saveSubscription(subscription);
|
||||||
}).then(function(subscription) {
|
}).catch(function(err) {
|
||||||
console.log('User is subscribed.');
|
console.log('Failed to subscribe the user: ', err);
|
||||||
saveSubscription(subscription);
|
});
|
||||||
}).catch(function(err) {
|
|
||||||
console.log('Failed to subscribe the user: ', err);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveSubscription(subscription) {
|
function saveSubscription(subscription) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user