Добавлен роутер на скачивание файлов
All checks were successful
Build And Push / publish (push) Successful in 2m44s

This commit is contained in:
2026-04-14 14:54:40 +03:00
parent 416bd576d9
commit ce8b0238ce
7 changed files with 67 additions and 10 deletions

View File

@ -5,7 +5,7 @@ from logging import getLogger
from secrets import token_urlsafe
from typing import Annotated
from fastapi import APIRouter, Body, Depends, Response, UploadFile, status
from fastapi import APIRouter, Body, Depends, UploadFile, status
from orjson import loads
from apps.remd.dependencies import convert_aemd_to_pdf, get_parsable_ids
@ -119,12 +119,21 @@ async def get_vaccs_report_download(
file_bytes = base64.b64decode(file.content)
filename = f'vaccs_report_{resultId or user.vita_id}.doc'
return Response(
content=file_bytes,
media_type='application/msword',
headers={'Content-Disposition': f'attachment; filename="{filename}"'},
temp_link_token = token_urlsafe(32)
await cache.set(
f'download:{temp_link_token}',
dumps(
{
'filename': filename,
'content_type': 'application/msword',
'data': file_bytes,
}
),
ex=600,
)
return s.DownloadFile(link=temp_link_token)
@router.get('/getMedExamDict')
async def get_med_exam_dict(user: Annotated[User, Depends(login)]):
@ -296,12 +305,21 @@ async def get_aemd_file_download(
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}"'},
temp_link_token = token_urlsafe(32)
await cache.set(
f'download:{temp_link_token}',
dumps(
{
'filename': filename,
'content_type': 'application/pdf',
'data': pdf_bytes,
}
),
ex=600,
)
return s.DownloadFile(link=temp_link_token)
@router.post('/measurement', status_code=status.HTTP_202_ACCEPTED)
async def measurement(

View File

@ -33,3 +33,7 @@ class Notifications(TypedDict):
class Complaints(BaseModel):
complaints: str
class DownloadFile(BaseModel):
link: str