v0.0.5: CSV отдельно, timestamp имена, прогресс в таблице
Deploy drhider / validate (push) Waiting to run

This commit is contained in:
2026-07-13 10:40:00 +04:00
parent 613b645456
commit e4975fb37e
4 changed files with 197 additions and 10 deletions
+26 -6
View File
@@ -1,20 +1,23 @@
"""
Blueprint: API DrHider.
Three endpoints:
Four endpoints:
- POST /api/upload — upload one file -> {session_id}
- POST /api/process/{sid} — process all session files -> {status:"done"}
- GET /api/download/{sid} — download ZIP
- GET /api/download/{sid} — download ZIP (with timestamp name)
- GET /api/csv/{sid} — download CSV separately
"""
import io
import zipfile
import traceback
from datetime import datetime
from flask import Blueprint, request, send_file, jsonify
from drhider import obfuscate_files, LLMClient
from drhider.builder import build_zip, build_mapping_csv
from session import create_session, add_file, get_files, store_result, get_result, cleanup, file_count
from session import (create_session, add_file, get_files, store_result,
get_result, store_csv, get_csv, cleanup, file_count)
api_bp = Blueprint("api", __name__, url_prefix="/api")
@@ -64,8 +67,10 @@ def process(sid):
elif not name.endswith("/"):
all_results.append((name, zf.read(name)))
csv_str = build_mapping_csv(all_mapping) if all_mapping else ""
final_zip = build_zip(all_results, mapping_csv=csv_str)
final_zip = build_zip(all_results) # CSV — отдельно, не в ZIP
store_result(sid, final_zip)
if csv_str:
store_csv(sid, csv_str)
return jsonify({"ok": True, "status": "done", "files": len(all_results)})
except Exception as e:
traceback.print_exc()
@@ -78,6 +83,21 @@ def download(sid):
zip_data = get_result(sid)
if zip_data is None:
return jsonify({"ok": False, "error": "Not found"}), 404
cleanup(sid)
ts = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
return send_file(io.BytesIO(zip_data), mimetype="application/zip",
as_attachment=True, download_name="drhider_output.zip")
as_attachment=True, download_name=f"drhider_{ts}.zip")
@api_bp.route("/csv/<sid>", methods=["GET"])
def csv_download(sid):
"""Download CSV separately."""
csv_str = get_csv(sid)
if csv_str is None:
return jsonify({"ok": False, "error": "Not found"}), 404
cleanup(sid)
ts = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
buf = io.BytesIO()
buf.write('\ufeff'.encode('utf-8') + csv_str.encode('utf-8'))
buf.seek(0)
return send_file(buf, mimetype="text/csv",
as_attachment=True, download_name=f"mapping_{ts}.csv")