diff --git a/site/app.py b/site/app.py index a70478a..d9200fe 100644 --- a/site/app.py +++ b/site/app.py @@ -110,38 +110,27 @@ def drhider(): @app.route("/api/drhider", methods=["POST"]) def api_drhider(): - """Обфускация: файлы → VM (LLM-NER) → ZIP.""" - import httpx + """Обфускация: файлы → LLM-NER → ZIP.""" + import io from flask import send_file + from services.drhider import obfuscate_files uploaded = request.files.getlist("files") if not uploaded: return jsonify({"ok": False, "error": "Нет файлов"}), 400 - # Отправляем файлы на VM - try: - files_data = [] - for f in uploaded: - if f.filename: - files_data.append(("files", (f.filename, f.read(), f.content_type or ""))) + files = [(f.filename, f.read(), f.content_type or "") for f in uploaded if f.filename] + if not files: + return jsonify({"ok": False, "error": "Нет файлов"}), 400 - with httpx.Client(timeout=300) as client: - resp = client.post(f"{VM_API}/api/drhider", files=files_data) - resp.raise_for_status() - except httpx.HTTPStatusError as e: - try: - detail = e.response.json().get("error", str(e)) - except Exception: - detail = str(e) - return jsonify({"ok": False, "error": detail}), 500 + try: + zip_data, _csv = obfuscate_files(files) + buf = io.BytesIO(zip_data) + buf.seek(0) + return send_file(buf, mimetype="application/zip", as_attachment=True, download_name="drhider_output.zip") except Exception as e: return jsonify({"ok": False, "error": str(e)}), 500 - import io - buf = io.BytesIO(resp.content) - buf.seek(0) - return send_file(buf, mimetype="application/zip", as_attachment=True, download_name="drhider_output.zip") - @app.route("/health") def health():