From 60e5adc70e6d388341b145dbf9f6c560d666c2f3 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 22 Jun 2024 14:49:00 -0700 Subject: [PATCH] enh: files api allow filename --- backend/apps/webui/routers/files.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/backend/apps/webui/routers/files.py b/backend/apps/webui/routers/files.py index 707dce9d3..3b6d44aa5 100644 --- a/backend/apps/webui/routers/files.py +++ b/backend/apps/webui/routers/files.py @@ -194,6 +194,29 @@ async def get_file_content_by_id(id: str, user=Depends(get_verified_user)): ) +@router.get("/{id}/content/{file_name}", response_model=Optional[FileModel]) +async def get_file_content_by_id(id: str, user=Depends(get_verified_user)): + file = Files.get_file_by_id(id) + + if file: + file_path = Path(file.meta["path"]) + + # Check if the file already exists in the cache + if file_path.is_file(): + print(f"file_path: {file_path}") + return FileResponse(file_path) + else: + raise HTTPException( + status_code=status.HTTP_404_NOT_FOUND, + detail=ERROR_MESSAGES.NOT_FOUND, + ) + else: + raise HTTPException( + status_code=status.HTTP_404_NOT_FOUND, + detail=ERROR_MESSAGES.NOT_FOUND, + ) + + ############################ # Delete File By Id ############################