Skip to content

Commit 98113ab

Browse files
committed
Fix: Switch to PostgreSQL and add asyncpg driver
1 parent bc9f1df commit 98113ab

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

app/app.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ async def upload_file(
4848
caption=caption,
4949
url=upload_result.url,
5050
file_type="video" if file.content_type.startswith("video/") else "image",
51-
file_name=upload_result.name
51+
file_name=upload_result.name,
52+
file_id=upload_result.file_id
5253

5354
)
5455
session.add(post)
@@ -115,6 +116,13 @@ async def delete_post(
115116
if post.user_id != user.id:
116117
raise HTTPException(status_code=403, detail="You are not authorized to delete this post")
117118

119+
try:
120+
imagekit.delete_file(file_id=post.file_id)
121+
except Exception as e:
122+
# We print the error but don't stop the function,
123+
# ensuring the post is deleted from DB even if ImageKit fails
124+
print(f"Error deleting from ImageKit: {e}")
125+
118126
await session.delete(post)
119127
await session.commit()
120128

app/db.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from sqlalchemy.orm import relationship
99
from sqlalchemy import ForeignKey
1010
from fastapi import Depends
11+
import os
1112

1213
DATABASE_URL = os.getenv("DATABASE_URL", "sqlite+aiosqlite:///./test.db?timeout=10")
1314

0 commit comments

Comments
 (0)