Добавлен роутер на скачивание файлов
All checks were successful
Build And Push / publish (push) Successful in 2m44s
All checks were successful
Build And Push / publish (push) Successful in 2m44s
This commit is contained in:
0
src/apps/download/__init__.py
Normal file
0
src/apps/download/__init__.py
Normal file
0
src/apps/download/v1/__init__.py
Normal file
0
src/apps/download/v1/__init__.py
Normal file
33
src/apps/download/v1/router.py
Normal file
33
src/apps/download/v1/router.py
Normal file
@ -0,0 +1,33 @@
|
||||
from logging import getLogger
|
||||
|
||||
from fastapi import APIRouter, Response
|
||||
from orjson import loads
|
||||
|
||||
from shared import exceptions as e
|
||||
from shared.redis import client as cache
|
||||
|
||||
logger = getLogger(__name__)
|
||||
router = APIRouter(
|
||||
prefix='/download',
|
||||
tags=[
|
||||
'Download',
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
@router.get('/{token}')
|
||||
async def download_file(token: str):
|
||||
file_data = await cache.get(f'download:{token}')
|
||||
|
||||
if file_data is None:
|
||||
raise e.NotFoundException
|
||||
|
||||
data = loads(file_data)
|
||||
|
||||
return Response(
|
||||
content=data['data'],
|
||||
media_type=data['content_type'],
|
||||
headers={
|
||||
'Content-Disposition': f'attachment; filename="{data["filename"]}"'
|
||||
},
|
||||
)
|
||||
@ -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(
|
||||
|
||||
@ -33,3 +33,7 @@ class Notifications(TypedDict):
|
||||
|
||||
class Complaints(BaseModel):
|
||||
complaints: str
|
||||
|
||||
|
||||
class DownloadFile(BaseModel):
|
||||
link: str
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
from apps.default.v1.router import router as default_router
|
||||
from apps.download.v1.router import router as download_router
|
||||
from apps.esia.v1.router import router as esia_router
|
||||
from apps.remd.v1.router import router as remd_router
|
||||
from apps.tmk.v1.router import router as tmk_router
|
||||
@ -17,6 +18,7 @@ router.include_router(users_router)
|
||||
router.include_router(remd_router)
|
||||
router.include_router(vitacore_router)
|
||||
router.include_router(tmk_router)
|
||||
router.include_router(download_router)
|
||||
|
||||
openapi_schema = get_openapi_schema(router)
|
||||
swagger_ui_html = get_swagger_html(router)
|
||||
|
||||
Reference in New Issue
Block a user