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 @@