freeleaps-service-hub/apps/central_storage/backend/business/document_manager.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

49 lines
1.9 KiB
Python

from backend.services.document_service import DocumentService
from backend.models.models import MediaType, DataFormat
from common.log.module_logger import ModuleLogger
class DocumentManager:
def __init__(self) -> None:
self.document_service = DocumentService()
self.module_logger = ModuleLogger(sender_id="DocumentManager")
async def retrieve_document_info(self, document_id: str):
await self.document_service.load_document(document_id=document_id)
download_link = (
await self.document_service.fetch_document_file_as_http_download()
)
file_name = self.document_service.get_file_name()
return {
"file_name": file_name,
"file_download_url": download_link,
}
async def read_document_file_as_http_media_data(self, document_id: str):
await self.document_service.load_document(document_id=document_id)
return await self.document_service.read_document_file_as_http_media_data()
async def upload_file(
self, associated_with: str, file_name: str, file_data: bytes
) -> bool:
await self.document_service.new_document(
file_name=file_name,
# This 'UNKNOWN' will make the document manager decide the media type from file name
media_type=MediaType.UNKNOWN,
data_format=DataFormat.RAW,
created_by=associated_with,
)
return await self.document_service.save_document_file(file_data) or None
# TODO: This should go to Freeleaps App
# add_doc = await self.attachment_service.add_document_to_request(
# request_id, document_id
# )
# await self.proposal_store.update_latest_proposal_with_documents(request_id)
async def delete_document(self, document_id: str):
await self.document_service.load_document(document_id=document_id)
await self.document_service.remove_document_file()
return