fix: DrHider via VM — managed Flask proxies, VM does LLM-NER obfuscation
Deploy contracts-flask / validate (push) Successful in 0s
Deploy contracts-flask / validate (push) Successful in 0s
This commit is contained in:
+21
-34
@@ -110,51 +110,38 @@ def drhider():
|
||||
|
||||
@app.route("/api/drhider", methods=["POST"])
|
||||
def api_drhider():
|
||||
"""Обфускация: файлы → ZIP с обезличенными копиями + mapping.csv."""
|
||||
import io
|
||||
import zipfile
|
||||
"""Обфускация: файлы → VM (LLM-NER) → ZIP."""
|
||||
import httpx
|
||||
from flask import send_file
|
||||
|
||||
uploaded = request.files.getlist("files")
|
||||
if not uploaded:
|
||||
return jsonify({"ok": False, "error": "Нет файлов"}), 400
|
||||
|
||||
files = []
|
||||
for f in uploaded:
|
||||
if not f.filename:
|
||||
continue
|
||||
content = f.read()
|
||||
files.append((f.filename, content, f.content_type or ""))
|
||||
|
||||
if not files:
|
||||
return jsonify({"ok": False, "error": "Нет файлов"}), 400
|
||||
|
||||
# Отправляем файлы на VM
|
||||
try:
|
||||
from services.drhider import obfuscate_files
|
||||
files_data = []
|
||||
for f in uploaded:
|
||||
if f.filename:
|
||||
files_data.append(("files", (f.filename, f.read(), f.content_type or "")))
|
||||
|
||||
llm = None
|
||||
if LLM_KEY:
|
||||
try:
|
||||
from services.llm_client import HttpxLLMClient
|
||||
llm = HttpxLLMClient(LLM_URL, LLM_KEY, LLM_MODEL)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
zip_data, csv_data = obfuscate_files(files, llm_client=llm)
|
||||
|
||||
buf = io.BytesIO()
|
||||
buf.write(zip_data)
|
||||
buf.seek(0)
|
||||
|
||||
return send_file(
|
||||
buf,
|
||||
mimetype="application/zip",
|
||||
as_attachment=True,
|
||||
download_name="drhider_output.zip"
|
||||
)
|
||||
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
|
||||
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():
|
||||
|
||||
Reference in New Issue
Block a user