fix: DrHider via VM — managed Flask proxies, VM does LLM-NER obfuscation
Deploy contracts-flask / validate (push) Successful in 0s

This commit is contained in:
2026-06-29 14:39:47 +04:00
parent e407696f6b
commit 853af0ff2f
2 changed files with 61 additions and 34 deletions
+40
View File
@@ -86,6 +86,8 @@ class Handler(BaseHTTPRequestHandler):
self._handle_api_prompts_delete()
elif self.path == "/api/sync":
self._handle_api_sync()
elif self.path == "/api/drhider":
self._handle_drhider()
else:
self.send_error(404)
@@ -210,6 +212,44 @@ class Handler(BaseHTTPRequestHandler):
execute("DELETE FROM contracts WHERE id NOT IN (SELECT DISTINCT contract_id FROM supplements)")
self._json({"ok": True, "deleted": deleted})
# ── POST /api/drhider ────────────────────────────────────────────────
def _handle_drhider(self):
"""Обфускация: multipart files → LLM-NER → ZIP."""
from services.drhider import obfuscate_files
from services.llm_client import HttpxLLMClient
from services.upload import parse_multipart
length = int(self.headers.get("Content-Length", 0))
raw = self.rfile.read(length)
ctype = self.headers.get("Content-Type", "")
files = parse_multipart(raw, ctype)
if not files:
self._json({"ok": False, "error": "Нет файлов"}, 400)
return
file_list = [(f.filename, f.content, f.content_type) for f in files]
try:
llm = HttpxLLMClient(
os.environ.get("LLM_API_URL", "https://api.aillm.ru/v1/chat/completions"),
os.environ.get("LLM_API_KEY", ""),
os.environ.get("LLM_MODEL", "gpt-oss-120b")
)
zip_data, _csv = obfuscate_files(file_list, llm_client=llm)
self.send_response(200)
self.send_header("Content-Type", "application/zip")
self.send_header("Content-Disposition", 'attachment; filename="drhider_output.zip"')
self.send_header("Content-Length", str(len(zip_data)))
self.end_headers()
self.wfile.write(zip_data)
except Exception as e:
import traceback
traceback.print_exc()
self._json({"ok": False, "error": str(e)}, 500)
# ── /api/groups ?batch=X ─────────────────────────────────────────────
def _handle_api_groups(self, parsed):