(feat:attachments) store filenames in worker

This commit is contained in:
ManishMadan2882
2025-06-03 04:02:41 +05:30
parent 9f911cb5cb
commit 7cab5b3b09
2 changed files with 24 additions and 1 deletions

View File

@@ -44,6 +44,7 @@ shared_conversations_collections = db["shared_conversations"]
users_collection = db["users"] users_collection = db["users"]
user_logs_collection = db["user_logs"] user_logs_collection = db["user_logs"]
user_tools_collection = db["user_tools"] user_tools_collection = db["user_tools"]
attachments_collection = db["attachments"]
agents_collection.create_index( agents_collection.create_index(
[("shared", 1)], [("shared", 1)],
@@ -236,13 +237,34 @@ class GetSingleConversation(Resource):
) )
if not conversation: if not conversation:
return make_response(jsonify({"status": "not found"}), 404) return make_response(jsonify({"status": "not found"}), 404)
# Process queries to include attachment names
queries = conversation["queries"]
for query in queries:
if "attachments" in query and query["attachments"]:
attachment_details = []
for attachment_id in query["attachments"]:
try:
attachment = attachments_collection.find_one(
{"_id": ObjectId(attachment_id)}
)
if attachment:
attachment_details.append({
"id": str(attachment["_id"]),
"filename": attachment.get("filename", "Unknown file")
})
except Exception as e:
current_app.logger.error(
f"Error retrieving attachment {attachment_id}: {e}", exc_info=True
)
query["attachments_metadata"] = attachment_details
except Exception as err: except Exception as err:
current_app.logger.error( current_app.logger.error(
f"Error retrieving conversation: {err}", exc_info=True f"Error retrieving conversation: {err}", exc_info=True
) )
return make_response(jsonify({"success": False}), 400) return make_response(jsonify({"success": False}), 400)
data = { data = {
"queries": conversation["queries"], "queries": queries,
"agent_id": conversation.get("agent_id"), "agent_id": conversation.get("agent_id"),
"is_shared_usage": conversation.get("is_shared_usage", False), "is_shared_usage": conversation.get("is_shared_usage", False),
"shared_token": conversation.get("shared_token", None), "shared_token": conversation.get("shared_token", None),

View File

@@ -475,6 +475,7 @@ def attachment_worker(self, file_info, user):
"_id": doc_id, "_id": doc_id,
"user": user, "user": user,
"path": relative_path, "path": relative_path,
"filename": filename,
"content": content, "content": content,
"token_count": token_count, "token_count": token_count,
"mime_type": mime_type, "mime_type": mime_type,