This commit is contained in:
2026-02-15 01:51:34 -06:00
parent ba8c6e9050
commit c29ec8e210
6 changed files with 183 additions and 18 deletions

View File

@@ -80,6 +80,43 @@ def register(app):
notifications.setNotificationSettings(user_uuid, {"web_push_enabled": True})
return flask.jsonify({"subscribed": True}), 201
@app.route("/api/notifications/settings", methods=["GET"])
def api_getNotificationSettings():
"""Return notification channel settings for the current user."""
user_uuid = _auth(flask.request)
if not user_uuid:
return flask.jsonify({"error": "unauthorized"}), 401
settings = notifications.getNotificationSettings(user_uuid)
if not settings:
return flask.jsonify({
"discord_webhook": "",
"discord_enabled": False,
"ntfy_topic": "",
"ntfy_enabled": False,
"web_push_enabled": False,
}), 200
return flask.jsonify({
"discord_webhook": settings.get("discord_webhook") or "",
"discord_enabled": bool(settings.get("discord_enabled")),
"ntfy_topic": settings.get("ntfy_topic") or "",
"ntfy_enabled": bool(settings.get("ntfy_enabled")),
"web_push_enabled": bool(settings.get("web_push_enabled")),
}), 200
@app.route("/api/notifications/settings", methods=["PUT"])
def api_updateNotificationSettings():
"""Update notification channel settings. Accepts partial updates."""
user_uuid = _auth(flask.request)
if not user_uuid:
return flask.jsonify({"error": "unauthorized"}), 401
data = flask.request.get_json()
if not data:
return flask.jsonify({"error": "missing body"}), 400
result = notifications.setNotificationSettings(user_uuid, data)
if not result:
return flask.jsonify({"error": "no valid fields provided"}), 400
return flask.jsonify({"updated": True}), 200
@app.route("/api/notifications/subscribe", methods=["DELETE"])
def api_pushUnsubscribe():
"""Remove a push subscription. Body: {endpoint}"""