fix: delete file

This commit is contained in:
Timothy Jaeryang Baek 2024-12-28 17:40:00 -08:00
parent e6e8978f78
commit 76decdba2a
3 changed files with 4 additions and 9 deletions

View File

@ -348,7 +348,7 @@ async def delete_file_by_id(id: str, user=Depends(get_verified_user)):
result = Files.delete_file_by_id(id) result = Files.delete_file_by_id(id)
if result: if result:
try: try:
Storage.delete_file(file.filename) Storage.delete_file(file.path)
except Exception as e: except Exception as e:
log.exception(e) log.exception(e)
log.error(f"Error deleting files") log.error(f"Error deleting files")

View File

@ -419,13 +419,6 @@ def remove_file_from_knowledge_by_id(
collection_name=knowledge.id, filter={"file_id": form_data.file_id} collection_name=knowledge.id, filter={"file_id": form_data.file_id}
) )
result = VECTOR_DB_CLIENT.query(
collection_name=knowledge.id,
filter={"file_id": form_data.file_id},
)
Files.delete_file_by_id(form_data.file_id)
if knowledge: if knowledge:
data = knowledge.data or {} data = knowledge.data or {}
file_ids = data.get("file_ids", []) file_ids = data.get("file_ids", [])

View File

@ -147,8 +147,10 @@ class StorageProvider:
return self._get_file_from_s3(file_path) return self._get_file_from_s3(file_path)
return self._get_file_from_local(file_path) return self._get_file_from_local(file_path)
def delete_file(self, filename: str) -> None: def delete_file(self, file_path: str) -> None:
"""Deletes a file either from S3 or the local file system.""" """Deletes a file either from S3 or the local file system."""
filename = file_path.split("/")[-1]
if self.storage_provider == "s3": if self.storage_provider == "s3":
self._delete_from_s3(filename) self._delete_from_s3(filename)