Update public source

This commit is contained in:
2026-10-09 14:23:52 +03:00
parent 3a710e1821
commit c6e55e2476
2 changed files with 190 additions and 6 deletions
+90 -6
View File
@@ -21,7 +21,10 @@ from cracklab.server.services.job_issuance import (
JobIssuanceError,
JobIssuanceService,
)
from cracklab.server.services.job_result import (
JobResultError,
JobResultService,
)
from cracklab.server.web import cracklab_bp
@@ -726,12 +729,93 @@ def clients_page():
)
@cracklab_bp.route("/results/")
@cracklab_bp.route("/results/", methods=["GET", "POST"])
def results_page():
return _placeholder(
"Results",
"Result history will be implemented here.",
"results",
error = None
message = None
result_summary = None
if request.method == "POST":
uploaded_file = request.files.get("result_package")
if uploaded_file is None or not uploaded_file.filename:
error = "Select a result ZIP package."
elif not uploaded_file.filename.lower().endswith(".zip"):
error = "Only ZIP packages are accepted."
else:
temp_path = None
try:
with tempfile.NamedTemporaryFile(
prefix="cracklab-result-",
suffix=".zip",
delete=False,
) as temp_file:
temp_path = Path(temp_file.name)
total_size = 0
max_size = 100 * 1024 * 1024
while True:
chunk = uploaded_file.stream.read(1024 * 1024)
if not chunk:
break
total_size += len(chunk)
if total_size > max_size:
raise ValueError(
"The ZIP package exceeds the 100 MB limit."
)
temp_file.write(chunk)
conn = connect_database()
try:
result_summary = JobResultService(conn).import_result(
temp_path
)
finally:
conn.close()
if result_summary["status"] == "ALREADY_IMPORTED":
message = (
f"Result for Job {result_summary['job_id']} "
"was already imported. No changes were made."
)
else:
message = (
f"Result for Job {result_summary['job_id']} "
"imported successfully."
)
except (JobResultError, ValueError) as exc:
error = str(exc)
except Exception:
error = (
"The result package could not be imported because "
"of an internal error. Check the application logs."
)
finally:
if temp_path is not None:
temp_path.unlink(missing_ok=True)
conn = connect_database()
try:
result_rows = ResultsRepository(conn).list_results()
finally:
conn.close()
return render_template(
"results.html",
active_page="results",
results=result_rows,
error=error,
message=message,
)