This commit is contained in:
Timothy J. Baek
2024-06-18 14:15:08 -07:00
parent 9e7b7a895e
commit 83986620ee
8 changed files with 66 additions and 11 deletions

View File

@@ -99,5 +99,14 @@ class FilesTable:
except:
return False
def delete_all_files(self) -> bool:
try:
query = File.delete()
query.execute() # Remove the rows, return number of rows removed.
return True
except:
return False
Files = FilesTable(DB)

View File

@@ -53,6 +53,7 @@ def upload_file(
# replace filename with uuid
id = str(uuid.uuid4())
filename = f"{id}_{filename}"
file_path = f"{UPLOAD_DIR}/{filename}"
contents = file.file.read()
@@ -143,3 +144,20 @@ async def delete_file_by_id(id: str, user=Depends(get_verified_user)):
status_code=status.HTTP_401_UNAUTHORIZED,
detail=ERROR_MESSAGES.NOT_FOUND,
)
############################
# Delete All Files
############################
@router.delete("/all")
async def delete_all_files(user=Depends(get_admin_user)):
result = Files.delete_all_files()
if result:
return {"message": "All files deleted successfully"}
else:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail=ERROR_MESSAGES.DEFAULT("Error deleting files"),
)