Spaces:
Running
Running
Anish commited on
Commit ·
9b8dcc7
1
Parent(s): 0dab55c
[Feature Updated] > Updated response for files such that, the video files only get the confidence and ai_explanation added, while image files do not.
Browse files- backend/app/api/file_routes.py +18 -26
backend/app/api/file_routes.py
CHANGED
|
@@ -12,6 +12,22 @@ from app.core.limiter import limiter
|
|
| 12 |
|
| 13 |
router = APIRouter(prefix="/files", tags=["files"])
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
@router.get("/my-files")
|
| 16 |
def list_user_files(
|
| 17 |
db: Session = Depends(get_db),
|
|
@@ -19,24 +35,10 @@ def list_user_files(
|
|
| 19 |
):
|
| 20 |
files = get_user_files(db, current_user.id)
|
| 21 |
|
| 22 |
-
|
| 23 |
if len(files) != 0:
|
| 24 |
return {
|
| 25 |
"total": len(files),
|
| 26 |
-
"files": [
|
| 27 |
-
{
|
| 28 |
-
"id": f.id,
|
| 29 |
-
"filename": f.filename,
|
| 30 |
-
"type": f.filetype,
|
| 31 |
-
"size": f.filesize,
|
| 32 |
-
"status": f.status,
|
| 33 |
-
"result": f.result,
|
| 34 |
-
"confidence": f.confidence,
|
| 35 |
-
"ai_explanation": f.ai_explanation,
|
| 36 |
-
"uploaded_at": f.created_at
|
| 37 |
-
}
|
| 38 |
-
for f in files
|
| 39 |
-
]
|
| 40 |
}
|
| 41 |
|
| 42 |
else:
|
|
@@ -52,17 +54,7 @@ def get_file(
|
|
| 52 |
):
|
| 53 |
file = get_file_detail(db, file_id, current_user.id)
|
| 54 |
|
| 55 |
-
return
|
| 56 |
-
"id": file.id,
|
| 57 |
-
"filename": file.filename,
|
| 58 |
-
"type": file.filetype,
|
| 59 |
-
"size": file.filesize,
|
| 60 |
-
"status": file.status,
|
| 61 |
-
"result": file.result,
|
| 62 |
-
"confidence": file.confidence,
|
| 63 |
-
"ai_explanation": file.ai_explanation,
|
| 64 |
-
"uploaded_at": file.created_at
|
| 65 |
-
}
|
| 66 |
|
| 67 |
@router.post("/upload")
|
| 68 |
@limiter.limit("5/minute")
|
|
|
|
| 12 |
|
| 13 |
router = APIRouter(prefix="/files", tags=["files"])
|
| 14 |
|
| 15 |
+
def format_file_response(f):
|
| 16 |
+
base_dict = {
|
| 17 |
+
"id": f.id,
|
| 18 |
+
"filename": f.filename,
|
| 19 |
+
"type": f.filetype,
|
| 20 |
+
"size": f.filesize,
|
| 21 |
+
"status": f.status,
|
| 22 |
+
"result": f.result,
|
| 23 |
+
"uploaded_at": f.created_at
|
| 24 |
+
}
|
| 25 |
+
# Only include confidence and explanation for videos
|
| 26 |
+
if f.filetype and f.filetype.startswith("video/"):
|
| 27 |
+
base_dict["confidence"] = f.confidence
|
| 28 |
+
base_dict["ai_explanation"] = f.ai_explanation
|
| 29 |
+
return base_dict
|
| 30 |
+
|
| 31 |
@router.get("/my-files")
|
| 32 |
def list_user_files(
|
| 33 |
db: Session = Depends(get_db),
|
|
|
|
| 35 |
):
|
| 36 |
files = get_user_files(db, current_user.id)
|
| 37 |
|
|
|
|
| 38 |
if len(files) != 0:
|
| 39 |
return {
|
| 40 |
"total": len(files),
|
| 41 |
+
"files": [format_file_response(f) for f in files]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
}
|
| 43 |
|
| 44 |
else:
|
|
|
|
| 54 |
):
|
| 55 |
file = get_file_detail(db, file_id, current_user.id)
|
| 56 |
|
| 57 |
+
return format_file_response(file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
@router.post("/upload")
|
| 60 |
@limiter.limit("5/minute")
|