From 24206d1e2f8a097d0d8fad6da704b521454c58d0 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Tue, 2 Jul 2024 01:08:38 +0100 Subject: [PATCH] Don't allow duplicate URLs --- src/main.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main.py b/src/main.py index 42f74b1..d2bc978 100644 --- a/src/main.py +++ b/src/main.py @@ -106,6 +106,10 @@ async def create_redirect( elif parsed.scheme not in ["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: case "urlsafe": slug = secrets.token_urlsafe(slug_length // 2)