Фикс скачивания файла
All checks were successful
Build And Push / publish (push) Successful in 3m48s
All checks were successful
Build And Push / publish (push) Successful in 3m48s
This commit is contained in:
@ -5,7 +5,6 @@ from logging import getLogger
|
||||
from secrets import token_urlsafe
|
||||
from typing import Annotated
|
||||
|
||||
import chardet
|
||||
from fastapi import APIRouter, Body, Depends, UploadFile, status
|
||||
from orjson import loads
|
||||
from xsdata.formats.dataclass.parsers.config import ParserConfig
|
||||
@ -120,27 +119,37 @@ async def get_vaccs_report_download(
|
||||
"""
|
||||
if resultId is not None:
|
||||
file = await c.vitacore_api.getDiagResultFile(resultId)
|
||||
|
||||
if file is None:
|
||||
raise e.BadRequestException
|
||||
|
||||
filename = f'vaccs_report_{resultId}'
|
||||
file_extension = 'pdf'
|
||||
content_type = 'application/pdf'
|
||||
xml_data = base64.b64decode(file.content)
|
||||
xml_data = xml_data.decode('utf-8').strip()
|
||||
xml_model = parser.from_string(xml_data, ClinicalDocument)
|
||||
file_string = xml_model.component.non_xmlbody.text.value.strip()
|
||||
|
||||
else:
|
||||
file = await c.vitacore_api.getVaccsReport(user.vita_id)
|
||||
|
||||
if file is None:
|
||||
raise e.BadRequestException
|
||||
if file is None:
|
||||
raise e.BadRequestException
|
||||
|
||||
filename = f'vaccs_report_{resultId or user.vita_id}.pdf'
|
||||
xml_data = base64.b64decode(file.content)
|
||||
result = chardet.detect(xml_data)
|
||||
xml_data = xml_data.decode(result['encoding'] or 'utf-8').strip()
|
||||
xml_model = parser.from_string(xml_data, ClinicalDocument)
|
||||
pdf_string = xml_model.component.non_xmlbody.text.value.strip()
|
||||
filename = f'vaccs_report_{token_urlsafe(10)}'
|
||||
file_extension = 'doc'
|
||||
content_type = 'application/msword'
|
||||
file_string = file.content
|
||||
|
||||
temp_link_token = token_urlsafe(32)
|
||||
await cache.set(
|
||||
f'download:{temp_link_token}',
|
||||
dumps(
|
||||
{
|
||||
'filename': filename,
|
||||
'content_type': 'application/pdf',
|
||||
'data': pdf_string,
|
||||
'filename': f'{filename}.{file_extension}',
|
||||
'content_type': content_type,
|
||||
'data': file_string,
|
||||
}
|
||||
),
|
||||
ex=600,
|
||||
|
||||
Reference in New Issue
Block a user