fmt+follows-refactored
This commit is contained in:
@@ -21,15 +21,11 @@ class WebhookEndpoint(HTTPEndpoint):
|
||||
raise HTTPException(status_code=400, detail="Request body is empty")
|
||||
auth = request.headers.get("Authorization")
|
||||
if not auth or auth != os.environ.get("WEBHOOK_SECRET"):
|
||||
raise HTTPException(
|
||||
status_code=401, detail="Invalid Authorization header"
|
||||
)
|
||||
raise HTTPException(status_code=401, detail="Invalid Authorization header")
|
||||
# logger.debug(data)
|
||||
user = data.get("user")
|
||||
if not isinstance(user, dict):
|
||||
raise HTTPException(
|
||||
status_code=400, detail="User data is not a dictionary"
|
||||
)
|
||||
raise HTTPException(status_code=400, detail="User data is not a dictionary")
|
||||
#
|
||||
name: str = (
|
||||
f"{user.get('given_name', user.get('slug'))} {user.get('middle_name', '')}"
|
||||
@@ -40,19 +36,13 @@ class WebhookEndpoint(HTTPEndpoint):
|
||||
pic: str = user.get("picture", "")
|
||||
if user_id:
|
||||
with local_session() as session:
|
||||
author = (
|
||||
session.query(Author).filter(Author.user == user_id).first()
|
||||
)
|
||||
author = session.query(Author).filter(Author.user == user_id).first()
|
||||
if not author:
|
||||
# If the author does not exist, create a new one
|
||||
slug: str = email.split("@")[0].replace(".", "-").lower()
|
||||
slug: str = re.sub("[^0-9a-z]+", "-", slug)
|
||||
while True:
|
||||
author = (
|
||||
session.query(Author)
|
||||
.filter(Author.slug == slug)
|
||||
.first()
|
||||
)
|
||||
author = session.query(Author).filter(Author.slug == slug).first()
|
||||
if not author:
|
||||
break
|
||||
slug = f"{slug}-{len(session.query(Author).filter(Author.email == email).all()) + 1}"
|
||||
@@ -66,9 +56,7 @@ class WebhookEndpoint(HTTPEndpoint):
|
||||
|
||||
return JSONResponse({"status": "success"})
|
||||
except HTTPException as e:
|
||||
return JSONResponse(
|
||||
{"status": "error", "message": str(e.detail)}, status_code=e.status_code
|
||||
)
|
||||
return JSONResponse({"status": "error", "message": str(e.detail)}, status_code=e.status_code)
|
||||
except Exception as e:
|
||||
import traceback
|
||||
|
||||
|
Reference in New Issue
Block a user