From 402c3460211656960c81cda51de227adb511f9a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Tue, 23 Jun 2026 08:25:30 +0400 Subject: [PATCH] =?UTF-8?q?v1.0.124:=20fix=20ZIP=20multipart=20=E2=80=94?= =?UTF-8?q?=20email.parser=20instead=20of=20buggy=20cgi.FieldStorage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/convert_server.py | 36 +++++++++++++++--------------------- index.cfm | 2 +- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/deploy/convert_server.py b/deploy/convert_server.py index 35dd2b5..261cb4f 100755 --- a/deploy/convert_server.py +++ b/deploy/convert_server.py @@ -279,36 +279,30 @@ class Handler(BaseHTTPRequestHandler): def _handle_unzip_upload(self): """Распаковать ZIP и загрузить каждый файл в Lucee. Только файлы из корня архива.""" - import zipfile, io, cgi, tempfile + import zipfile, io + from email.parser import BytesParser - # CORS preflight уже обработан nginx, но на всякий случай - self._send_cors() - - # Парсим multipart через cgi.FieldStorage content_type = self.headers.get("Content-Type", "") length = int(self.headers.get("Content-Length", 0)) body = self.rfile.read(length) - # Сохраняем тело во временный файл для cgi.FieldStorage - fp = tempfile.TemporaryFile() - fp.write(body) - fp.seek(0) + # Парсим multipart через email.parser + msg = BytesParser().parsebytes( + b"Content-Type: " + content_type.encode() + b"\r\n\r\n" + body + ) + zip_data = None + if msg.is_multipart(): + for part in msg.get_payload(): + if part.get_filename(): + zip_data = part.get_payload(decode=True) + break + else: + zip_data = body - env = os.environ.copy() - env["REQUEST_METHOD"] = "POST" - env["CONTENT_TYPE"] = content_type - env["CONTENT_LENGTH"] = str(length) - - form = cgi.FieldStorage(fp=fp, environ=env, keep_blank_values=True) - file_item = form.getfirst("file") or form.getfirst("files") - if not file_item or not file_item.file: + if not zip_data: self._send_error_cors(400, "no file in request") - fp.close() return - zip_data = file_item.file.read() - fp.close() - results = [] try: with zipfile.ZipFile(io.BytesIO(zip_data)) as zf: diff --git a/index.cfm b/index.cfm index 0992a9f..2a6426e 100644 --- a/index.cfm +++ b/index.cfm @@ -75,7 +75,7 @@
Nubes - Сверка договоров — LLM AI-driven Event Sourcing v1.0.123 — Lucee + Сверка договоров — LLM AI-driven Event Sourcing v1.0.124 — Lucee