47 lines
1.8 KiB
Python
47 lines
1.8 KiB
Python
from backend.services.document_service import DocumentService
|
|
from backend.models.models import MediaType, DataFormat
|
|
|
|
|
|
class DocumentManager:
|
|
def __init__(self) -> None:
|
|
self.document_service = DocumentService()
|
|
|
|
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
|