freeleaps-service-hub/apps/content/backend/document/document_manager.py

31 lines
1.4 KiB
Python

from common.config.app_settings import app_settings
import httpx
class DocumentManager:
def __init__(self):
self.storage_service_api_base = app_settings.CENTRAL_STORAGE_WEBAPI_URL_BASE.rstrip('/') + '/'
async def retrieve_document_info(self, document_id:str):
api_url = self.storage_service_api_base + "retrieve_document_info/" + document_id
async with httpx.AsyncClient() as client:
response = await client.get(api_url)
return response.json()
async def retrieve_document_as_http_media(self, document_id:str):
api_url = self.storage_service_api_base + "read-document-as-http-media/" + document_id
async with httpx.AsyncClient() as client:
response = await client.get(api_url)
return response.json()
async def save_document_file(self,associated_with:str, name:str,blob:bytes)->str:
api_url = self.storage_service_api_base + "upload-file"
files = {'file':(name,blob)}
async with httpx.AsyncClient() as client:
response = await client.post(api_url,
data={
'associated_with':associated_with
},
files=files
)
return response.json()['document_id']