v1.0.134: ALL uploads through VM — /upload proxy avoids Lucee multipart crash

This commit is contained in:
2026-06-23 09:04:47 +04:00
parent 9c7a5a9975
commit 21914d1763
3 changed files with 54 additions and 2 deletions
+43
View File
@@ -62,6 +62,8 @@ class Handler(BaseHTTPRequestHandler):
self._handle_llm_ops()
elif self.path == "/unzip-upload":
self._handle_unzip_upload()
elif self.path == "/upload":
self._handle_upload()
else:
self._handle_doc_convert()
@@ -277,6 +279,47 @@ class Handler(BaseHTTPRequestHandler):
self.end_headers()
self.wfile.write(json.dumps({"error": str(e)}, ensure_ascii=False).encode())
def _handle_upload(self):
"""Принять файл и передать в Lucee через JSON API (обходит multipart-краш Lucee)."""
from email.parser import BytesParser
content_type = self.headers.get("Content-Type", "")
length = int(self.headers.get("Content-Length", 0))
body = self.rfile.read(length)
# Парсим multipart
msg = BytesParser().parsebytes(
b"Content-Type: " + content_type.encode() + b"\r\n\r\n" + body
)
filename = None
file_data = None
if msg.is_multipart():
for part in msg.get_payload():
fn = part.get_filename()
if fn:
filename = fn
file_data = part.get_payload(decode=True)
break
if not filename or not file_data:
self._send_error_cors(400, "no file in request")
return
# Шлём в Lucee через JSON API (не multipart!)
resp = httpx.post(
f"{LUCEE_URL}/upload.cfm",
json={"filename": filename, "data": "\\x" + file_data.hex()},
timeout=60
)
self._send_cors()
if resp.status_code == 200:
self.send_response(200)
self.send_header("Content-Type", "application/json; charset=utf-8")
self.end_headers()
self.wfile.write(resp.content)
else:
self._send_error_cors(502, f"Lucee error: {resp.status_code}")
def _handle_unzip_upload(self):
"""Распаковать ZIP и загрузить каждый файл в Lucee. Только файлы из корня архива."""
import zipfile, io