add 'read document as http media'
This commit is contained in:
parent
154c0a4d36
commit
4ebf8579db
@ -11,6 +11,9 @@ class DocumentHub:
|
|||||||
async def retrieve_document_info(self, document_id: str):
|
async def retrieve_document_info(self, document_id: str):
|
||||||
return await self.document_manager.retrieve_document_info(document_id)
|
return await self.document_manager.retrieve_document_info(document_id)
|
||||||
|
|
||||||
|
async def read_document_file_as_http_media_data(self, document_id: str):
|
||||||
|
return await self.document_manager.read_document_file_as_http_media_data(document_id)
|
||||||
|
|
||||||
async def upload_document(
|
async def upload_document(
|
||||||
self, associated_with: str, file_name: str, file_data: bytes
|
self, associated_with: str, file_name: str, file_data: bytes
|
||||||
) -> bool:
|
) -> bool:
|
||||||
|
|||||||
@ -18,6 +18,12 @@ class DocumentManager:
|
|||||||
"file_download_url": download_link,
|
"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(
|
async def upload_file(
|
||||||
self, associated_with: str, file_name: str, file_data: bytes
|
self, associated_with: str, file_name: str, file_data: bytes
|
||||||
) -> bool:
|
) -> bool:
|
||||||
|
|||||||
@ -0,0 +1,37 @@
|
|||||||
|
from fastapi import APIRouter
|
||||||
|
from infra.token.token_manager import TokenManager
|
||||||
|
from fastapi import APIRouter, Depends
|
||||||
|
from fastapi.encoders import jsonable_encoder
|
||||||
|
from fastapi.responses import JSONResponse
|
||||||
|
from fastapi import Depends, HTTPException
|
||||||
|
from starlette.status import HTTP_401_UNAUTHORIZED
|
||||||
|
from fastapi.encoders import jsonable_encoder
|
||||||
|
from fastapi.responses import JSONResponse
|
||||||
|
from infra.token.token_manager import TokenManager
|
||||||
|
from app.central_storage.backend.application.document_hub import DocumentHub
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
|
# Web API
|
||||||
|
# read document as http media
|
||||||
|
@router.get(
|
||||||
|
"/read-document-as-http-media/{document_id}",
|
||||||
|
operation_id="read-document-as-http-media",
|
||||||
|
summary="Read document as http media",
|
||||||
|
description="Read document as http media which can be used by html directly",
|
||||||
|
response_description="The http media which can be used by html directly",
|
||||||
|
)
|
||||||
|
async def read_document_as_http_media(
|
||||||
|
document_id: str
|
||||||
|
):
|
||||||
|
|
||||||
|
# Fetch the document using DocumentHub
|
||||||
|
media = await DocumentHub().read_document_file_as_http_media_data(document_id)
|
||||||
|
|
||||||
|
# If document is not found, raise 404 error
|
||||||
|
if not media:
|
||||||
|
raise HTTPException(status_code=404, detail="Document not found")
|
||||||
|
|
||||||
|
# Return the document details
|
||||||
|
return JSONResponse(content=jsonable_encoder({"media": media}))
|
||||||
Loading…
Reference in New Issue
Block a user