diff --git a/backend/modules/notification/repository/notifications.py b/backend/modules/notification/repository/notifications.py index c8c0801bf..241a93d34 100644 --- a/backend/modules/notification/repository/notifications.py +++ b/backend/modules/notification/repository/notifications.py @@ -28,6 +28,10 @@ class Notifications(NotificationInterface): notification_id, notification, ): + if notification_id is None: + logger.info("Notification id is required") + return None + """Update a notification by id""" response = ( self.db.from_("notifications") diff --git a/backend/modules/notification/service/notification_service.py b/backend/modules/notification/service/notification_service.py index 80e0399c1..06437562d 100644 --- a/backend/modules/notification/service/notification_service.py +++ b/backend/modules/notification/service/notification_service.py @@ -44,5 +44,7 @@ class NotificationService: """ Update a notification """ - - return self.repository.update_notification_by_id(notification_id, notification) + if notification: + return self.repository.update_notification_by_id( + notification_id, notification + ) diff --git a/backend/modules/upload/controller/upload_routes.py b/backend/modules/upload/controller/upload_routes.py index 36f1cfb7a..9227bac82 100644 --- a/backend/modules/upload/controller/upload_routes.py +++ b/backend/modules/upload/controller/upload_routes.py @@ -85,7 +85,7 @@ async def upload_file( "name": uploadFile.filename if uploadFile else "Last Upload File", } notification_service.update_notification_by_id( - upload_notification.id, + upload_notification.id if upload_notification else None, NotificationUpdatableProperties( status=NotificationsStatusEnum.Done, message=str(notification_message), diff --git a/backend/repository/files/upload_file.py b/backend/repository/files/upload_file.py index e61b5d755..19eb58c77 100644 --- a/backend/repository/files/upload_file.py +++ b/backend/repository/files/upload_file.py @@ -1,4 +1,5 @@ import json +import os from multiprocessing import get_logger from langchain.pydantic_v1 import Field @@ -8,14 +9,48 @@ from supabase.client import Client logger = get_logger() +# Mapping of file extensions to MIME types +mime_types = { + ".txt": "text/plain", + ".csv": "text/csv", + ".md": "text/markdown", + ".markdown": "text/markdown", + ".telegram": "application/x-telegram", + ".m4a": "audio/mp4", + ".mp3": "audio/mpeg", + ".webm": "audio/webm", + ".mp4": "video/mp4", + ".mpga": "audio/mpeg", + ".wav": "audio/wav", + ".mpeg": "video/mpeg", + ".pdf": "application/pdf", + ".html": "text/html", + ".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation", + ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + ".odt": "application/vnd.oasis.opendocument.text", + ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + ".xls": "application/vnd.ms-excel", + ".epub": "application/epub+zip", + ".ipynb": "application/x-ipynb+json", + ".py": "text/x-python", +} + def upload_file_storage(file, file_identifier: str): supabase_client: Client = get_supabase_client() - # res = supabase_client.storage.create_bucket("quivr") response = None try: - response = supabase_client.storage.from_("quivr").upload(file_identifier, file) + # Get the file extension + _, file_extension = os.path.splitext(file_identifier) + + # Get the MIME type for the file extension + mime_type = mime_types.get(file_extension, "text/html") + + response = supabase_client.storage.from_("quivr").upload( + file_identifier, file, file_options={"content-type": mime_type} + ) + return response except Exception as e: logger.error(e)