Updatex
All checks were successful
DevPlace CI / test (push) Successful in 6m41s

This commit is contained in:
retoor 2026-05-29 00:49:37 +02:00
parent 3a4c6b14d5
commit 3f900b4002
2 changed files with 9 additions and 8 deletions

View File

@ -250,7 +250,7 @@ async def notify_user(user_uid: str, payload: dict[str, Any]) -> None:
async def register( async def register(
user_uid: str, endpoint: str, key_auth: str, key_p256dh: str user_uid: str, endpoint: str, key_auth: str, key_p256dh: str
) -> dict[str, Any]: ) -> tuple[dict[str, Any], bool]:
table = get_table("push_registration") table = get_table("push_registration")
existing = table.find_one( existing = table.find_one(
user_uid=user_uid, user_uid=user_uid,
@ -261,7 +261,7 @@ async def register(
) )
if existing: if existing:
logger.debug("Push subscription already registered for user %s", user_uid) logger.debug("Push subscription already registered for user %s", user_uid)
return existing return existing, False
record = { record = {
"uid": generate_uid(), "uid": generate_uid(),
@ -274,4 +274,4 @@ async def register(
} }
table.insert(record) table.insert(record)
logger.info("Registered push subscription for user %s", user_uid) logger.info("Registered push subscription for user %s", user_uid)
return record return record, True

View File

@ -35,17 +35,18 @@ async def push_register(request: Request) -> JSONResponse:
if not (isinstance(keys, dict) and body.get("endpoint") and keys.get("p256dh") and keys.get("auth")): if not (isinstance(keys, dict) and body.get("endpoint") and keys.get("p256dh") and keys.get("auth")):
return JSONResponse({"error": "Invalid request"}, status_code=400) return JSONResponse({"error": "Invalid request"}, status_code=400)
await push.register( _, created = await push.register(
user_uid=user["uid"], user_uid=user["uid"],
endpoint=body["endpoint"], endpoint=body["endpoint"],
key_auth=keys["auth"], key_auth=keys["auth"],
key_p256dh=keys["p256dh"], key_p256dh=keys["p256dh"],
) )
try: if created:
await push.notify_user(user["uid"], WELCOME_PAYLOAD) try:
except Exception as exc: await push.notify_user(user["uid"], WELCOME_PAYLOAD)
logger.warning("Welcome push failed for %s: %s", user["uid"], exc) except Exception as exc:
logger.warning("Welcome push failed for %s: %s", user["uid"], exc)
return JSONResponse({"registered": True}) return JSONResponse({"registered": True})