freeleaps-service-hub/apps/central_storage/backend/application/document_hub.py
Nicolas 5f8b6ed575 The log format of the central storage has been adjusted so that it can actively write corresponding logs to the log files.
Simultaneously upgraded the mirror versions of authentication and central storage.
2025-09-23 10:08:39 +08:00

50 lines
2.0 KiB
Python

from backend.business.document_manager import (
DocumentManager,
)
from common.log.module_logger import ModuleLogger
class DocumentHub:
def __init__(
self,
):
self.document_manager = DocumentManager()
self.module_logger = ModuleLogger(sender_id="DocumentHub")
return
async def retrieve_document_info(self, document_id: str):
await self.module_logger.log_info(f"Retrieving document info for ID: {document_id}")
result = await self.document_manager.retrieve_document_info(document_id)
await self.module_logger.log_info(f"Document info retrieved successfully for ID: {document_id}")
return result
async def read_document_file_as_http_media_data(self, document_id: str):
await self.module_logger.log_info(f"Reading document as HTTP media for ID: {document_id}")
result = await self.document_manager.read_document_file_as_http_media_data(
document_id
)
await self.module_logger.log_info(f"Document media data read successfully for ID: {document_id}")
return result
async def upload_document(
self, associated_with: str, file_name: str, file_data: bytes
) -> bool:
"""Upload a file
Args:
file_name: the name of the file
file (bytes): the file to be uploaded
"""
await self.module_logger.log_info(f"Uploading document {file_name} for user {associated_with}")
result = await self.document_manager.upload_file(
associated_with, file_name, file_data
)
await self.module_logger.log_info(f"Document upload completed for {file_name}, result: {result}")
return result
async def delete_documents(self, document_ids: list):
await self.module_logger.log_info(f"Deleting documents: {document_ids}")
for document_id in document_ids:
await self.document_manager.delete_document(document_id)
await self.module_logger.log_info(f"Documents deleted successfully: {document_ids}")
return