(feat:attch) store file mime type

This commit is contained in:
ManishMadan2882
2025-04-07 20:16:03 +05:30
parent 1f3d1cc73e
commit 0c1138179b

View File

@@ -328,6 +328,7 @@ def attachment_worker(self, directory, file_info, user):
""" """
import datetime import datetime
import os import os
import mimetypes
from application.utils import num_tokens_from_string from application.utils import num_tokens_from_string
mongo = MongoDB.get_client() mongo = MongoDB.get_client()
@@ -361,6 +362,8 @@ def attachment_worker(self, directory, file_info, user):
file_path_relative = f"{settings.UPLOAD_FOLDER}/{user}/attachments/{attachment_id}/{filename}" file_path_relative = f"{settings.UPLOAD_FOLDER}/{user}/attachments/{attachment_id}/{filename}"
mime_type = mimetypes.guess_type(file_path)[0] or 'application/octet-stream'
doc_id = ObjectId(attachment_id) doc_id = ObjectId(attachment_id)
attachments_collection.insert_one({ attachments_collection.insert_one({
"_id": doc_id, "_id": doc_id,
@@ -368,6 +371,7 @@ def attachment_worker(self, directory, file_info, user):
"path": file_path_relative, "path": file_path_relative,
"content": content, "content": content,
"token_count": token_count, "token_count": token_count,
"mime_type": mime_type,
"date": datetime.datetime.now(), "date": datetime.datetime.now(),
}) })
@@ -380,7 +384,8 @@ def attachment_worker(self, directory, file_info, user):
"filename": filename, "filename": filename,
"path": file_path_relative, "path": file_path_relative,
"token_count": token_count, "token_count": token_count,
"attachment_id": attachment_id "attachment_id": attachment_id,
"mime_type": mime_type
} }
else: else:
logging.warning("No content was extracted from the file", logging.warning("No content was extracted from the file",