aboutsummaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorParker <contact@pkrm.dev>2024-11-03 16:31:15 -0600
committerParker <contact@pkrm.dev>2024-11-03 16:31:15 -0600
commitdb1857a18f08ec47bc585c9c3c10b4a8fcb74f1f (patch)
treec9bfc8ea1a3fdd7eff64b5cc295e8c890e2643b2 /api
parentde4dc0bc5b0196f09bb134df5374d169cc02b426 (diff)
Make links case-insensitive
Diffstat (limited to 'api')
-rw-r--r--api/routes/links_route.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/api/routes/links_route.py b/api/routes/links_route.py
index fd0a77a..4385712 100644
--- a/api/routes/links_route.py
+++ b/api/routes/links_route.py
@@ -37,19 +37,21 @@ async def create_link(
# Check if the URL is valid
if not validators.url(url.url):
raise HTTPException(
- status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail="Invalid URL"
+ status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
+ detail="Invalid URL",
)
# Create the new link and add it to the database
while True:
try:
link_path = "".join(
random.choices(string.ascii_uppercase + "1234567890", k=5)
- )
+ ).upper()
new_link = Link(
link=link_path,
owner=api_key["owner"],
redirect_link=url.url,
- expire_date=datetime.datetime.now() + datetime.timedelta(days=30),
+ expire_date=datetime.datetime.now()
+ + datetime.timedelta(days=30),
)
db.add(new_link)
db.commit()
@@ -70,6 +72,7 @@ async def delete_link(
db=Depends(get_db),
api_key: str = Security(check_api_key),
):
+ link = link.upper()
# Get the link and check the owner
link = db.query(Link).filter(Link.link == link).first()
if not link:
@@ -93,12 +96,16 @@ async def delete_link(
return {"response": "Link successfully deleted", "link": link.link}
-@router.get("/{link}/records", summary="Get all of the IP log records associated with a link")
+@router.get(
+ "/{link}/records",
+ summary="Get all of the IP log records associated with a link",
+)
async def get_link_records(
link: Annotated[str, Path(title="Link to get records for")],
db=Depends(get_db),
api_key: str = Security(check_api_key),
):
+ link = link.upper()
# Get the link and check the owner
link = db.query(Link).filter(Link.link == link).first()
if not link:
@@ -116,12 +123,16 @@ async def get_link_records(
return records
-@router.delete("/{link}/records", summary="Delete all of the IP log records associated with a link")
+@router.delete(
+ "/{link}/records",
+ summary="Delete all of the IP log records associated with a link",
+)
async def delete_link_records(
link: Annotated[str, Path(title="Link to delete records for")],
db=Depends(get_db),
api_key: str = Security(check_api_key),
):
+ link = link.upper()
# Get the link and check the owner
link = db.query(Link).filter(Link.link == link).first()
if not link: