сырой разбор JSON (regex, без get_json), v1.40

This commit is contained in:
2026-06-17 22:34:36 +04:00
parent 59f8ac3652
commit 9bae90e9a0
2 changed files with 14 additions and 10 deletions
+13 -9
View File
@@ -142,22 +142,26 @@ class ContractsApp:
# ── Загрузка base64 (JSON) ──────────────────────────────────
def _upload_json(self):
"""Принять файл как base64. Сохранить строкой (без декодирования — быстро)."""
"""Принять файл как base64. Без JSON-парсинга — сырой разбор."""
_log("upload_entry", "start")
try:
data = request.get_json(silent=True)
_log("upload_json_parsed", f"data={'yes' if data else 'no'} len={len(request.data) if request.data else 0}")
if not data:
return jsonify({"error": "Нет JSON"}), 400
raw = request.get_data(as_text=True)
import re
m = re.search(r'"data"\s*:\s*"([^"]*)"', raw)
if not m:
return jsonify({"error": "Нет data"}), 400
b64 = m.group(1)
m = re.search(r'"filename"\s*:\s*"([^"]*)"', raw)
filename = m.group(1) if m else ""
m = re.search(r'"cid"\s*:\s*"([^"]*)"', raw)
cid = m.group(1) if m else None
filename = data.get("filename", "")
b64 = data.get("data", "")
_log("upload", f"file={filename} b64={len(b64) if b64 else 0}")
if not filename or not b64:
return jsonify({"error": "Нет filename или data"}), 400
mime = mimeutil.guess_mime(filename) or "application/octet-stream"
cid = data.get("cid")
# Контракт — синхронно (быстро, нужно для следующих загрузок)
if not cid: