Don't allow duplicate URLs
All checks were successful
Build and Publish / build_and_publish (push) Successful in 31s

This commit is contained in:
Nexus 2024-07-02 01:08:38 +01:00
parent fd00b98346
commit 24206d1e2f
Signed by: nex
GPG key ID: 0FA334385D0B689F

View file

@ -106,6 +106,10 @@ async def create_redirect(
elif parsed.scheme not in ["http", "https"]: elif parsed.scheme not in ["http", "https"]:
raise HTTPException(status_code=400, detail="Invalid URL - must be HTTP/HTTPS") raise HTTPException(status_code=400, detail="Invalid URL - must be HTTP/HTTPS")
existing = await db.Redirect.get_or_none(destination=destination)
if existing is not None:
return await db.RedirectPydantic.from_tortoise_orm(existing)
match slug_type: match slug_type:
case "urlsafe": case "urlsafe":
slug = secrets.token_urlsafe(slug_length // 2) slug = secrets.token_urlsafe(slug_length // 2)