Добавлен эндпоинт на скачивание файла
All checks were successful
Build And Push / publish (push) Successful in 3m35s
All checks were successful
Build And Push / publish (push) Successful in 3m35s
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "HospitalAssistantBackend"
|
||||
version = "1.2.1"
|
||||
version = "1.3.0"
|
||||
description = "Backend for Hospital Assistant"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.13,<3.14"
|
||||
|
||||
@ -5,7 +5,7 @@ from logging import getLogger
|
||||
from secrets import token_urlsafe
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, Body, Depends, UploadFile, status
|
||||
from fastapi import APIRouter, Body, Depends, Response, UploadFile, status
|
||||
from orjson import loads
|
||||
|
||||
from apps.remd.dependencies import convert_aemd_to_pdf, get_parsable_ids
|
||||
@ -257,6 +257,27 @@ async def get_aemd_file(
|
||||
}
|
||||
|
||||
|
||||
@router.get('/aemd/{emdrId}/download')
|
||||
async def get_aemd_file_download(
|
||||
user: Annotated[User, Depends(login)], emdrId: str, docKind: str
|
||||
):
|
||||
data = await cache.get(f'aemd:{user.vita_id}:{emdrId}')
|
||||
|
||||
if not data:
|
||||
raise e.NotFoundException(status_code=404, detail='File not found')
|
||||
|
||||
b64 = loads(data)['data']
|
||||
decoded = base64.b64decode(b64)
|
||||
pdf_bytes = await convert_aemd_to_pdf(decoded, docKind)
|
||||
filename = f'{emdrId}.pdf'
|
||||
|
||||
return Response(
|
||||
content=pdf_bytes,
|
||||
media_type='application/pdf',
|
||||
headers={'Content-Disposition': f'attachment; filename="{filename}"'},
|
||||
)
|
||||
|
||||
|
||||
@router.post('/measurement', status_code=status.HTTP_202_ACCEPTED)
|
||||
async def measurement(
|
||||
tdn_access_token: Annotated[str, Depends(token)],
|
||||
|
||||
Reference in New Issue
Block a user