Попытка фикса кодировки
All checks were successful
Build And Push / publish (push) Successful in 2m48s

This commit is contained in:
2026-04-15 18:47:05 +03:00
parent 38dd796683
commit c1c176d642
2 changed files with 5 additions and 2 deletions

View File

@ -1,6 +1,6 @@
[project] [project]
name = "HospitalAssistantBackend" name = "HospitalAssistantBackend"
version = "1.5.8" version = "1.5.9"
description = "Backend for Hospital Assistant" description = "Backend for Hospital Assistant"
readme = "README.md" readme = "README.md"
requires-python = ">=3.13,<3.14" requires-python = ">=3.13,<3.14"
@ -37,6 +37,7 @@ dependencies = [
"typer-slim==0.16.1", "typer-slim==0.16.1",
"xsdata[cli]>=26.2", "xsdata[cli]>=26.2",
"xsdata-pydantic>=24.5", "xsdata-pydantic>=24.5",
"chardet>=7.4.3",
] ]
[dependency-groups] [dependency-groups]

View File

@ -5,6 +5,7 @@ from logging import getLogger
from secrets import token_urlsafe from secrets import token_urlsafe
from typing import Annotated from typing import Annotated
import chardet
from fastapi import APIRouter, Body, Depends, UploadFile, status from fastapi import APIRouter, Body, Depends, UploadFile, status
from orjson import loads from orjson import loads
from xsdata.formats.dataclass.parsers.config import ParserConfig from xsdata.formats.dataclass.parsers.config import ParserConfig
@ -127,7 +128,8 @@ async def get_vaccs_report_download(
filename = f'vaccs_report_{resultId or user.vita_id}.pdf' filename = f'vaccs_report_{resultId or user.vita_id}.pdf'
xml_data = base64.b64decode(file.content) xml_data = base64.b64decode(file.content)
xml_data = xml_data.decode('utf-8').strip() result = chardet.detect(xml_data)
xml_data = xml_data.decode(result['encoding'] or 'utf-8').strip()
xml_model = parser.from_string(xml_data, ClinicalDocument) xml_model = parser.from_string(xml_data, ClinicalDocument)
pdf_string = xml_model.component.non_xmlbody.text.value.strip() pdf_string = xml_model.component.non_xmlbody.text.value.strip()