author-hook-fix-2
All checks were successful
deploy / deploy (push) Successful in 1m27s

This commit is contained in:
Untone 2023-12-15 17:37:32 +03:00
parent f9afe3d9dd
commit a8ee8cde0b

View File

@ -1,4 +1,5 @@
import os import os
import re
from importlib import import_module from importlib import import_module
from os.path import exists from os.path import exists
from ariadne import load_schema_from_path, make_executable_schema from ariadne import load_schema_from_path, make_executable_schema
@ -66,12 +67,8 @@ class WebhookEndpoint(HTTPEndpoint):
if auth: if auth:
if auth == os.environ.get("WEBHOOK_SECRET"): if auth == os.environ.get("WEBHOOK_SECRET"):
user_id = data["user"]["id"] user_id = data["user"]["id"]
slug = ( slug = (data["user"]["preferred_username"] or data["user"]["email"]).split("@")[0].lowercase()
(data["user"]["preferred_username"] or data["user"]["email"]) slug = re.sub("[^0-9a-zA-Z]+", "-", slug or "")
.replace(".", "-")
.split("@")
.pop()
)
await create_author(user_id, slug) await create_author(user_id, slug)
return JSONResponse({"status": "success"}) return JSONResponse({"status": "success"})
except Exception as e: except Exception as e: