holder: cap total cells at 1000 to prevent runaway renders
User-triggered 120x120 = 14400 cells, which produces huge STL/long renders. Total cells is the right metric (CSG cost scales with count, not max axis), so cap by N = rows*cols (or rows*(rows+1)/2 for tria style). 1000 covers any realistic pack (e.g. 20x50) while blocking accidental misuse. Backend: - holder.py: MAX_CELLS env-tunable (default 1000); expected_cell_count and _check_cell_limit raise ValueError on exceed; both compute_cells() and render_stl() call it up-front. - app.py: /api/holder/render now returns 400 on ValueError (not 500) so the frontend can distinguish bad input from server failure. /api/holder/params now publishes max_cells alongside the schema. Frontend: - holder-app.js: reads max_cells from the params endpoint; status shows "N cells / over limit (1000)" in red and disables the Render and "Design busbars" buttons when exceeded. - holder.css: .topbar-status.over-limit style (red, bold).
This commit is contained in:
@@ -56,7 +56,11 @@ def health():
|
||||
@app.get("/api/holder/params")
|
||||
def holder_params():
|
||||
"""Schema for the parameter form + their defaults."""
|
||||
return jsonify({"params": holder.schema_dict(), "defaults": holder.default_params()})
|
||||
return jsonify({
|
||||
"params": holder.schema_dict(),
|
||||
"defaults": holder.default_params(),
|
||||
"max_cells": holder.MAX_CELLS,
|
||||
})
|
||||
|
||||
|
||||
@app.post("/api/holder/render")
|
||||
@@ -65,6 +69,8 @@ def holder_render():
|
||||
body = request.get_json(silent=True) or {}
|
||||
try:
|
||||
data = holder.render_stl(body.get("params", {}))
|
||||
except ValueError as e:
|
||||
return jsonify({"error": str(e)}), 400
|
||||
except (FileNotFoundError, RuntimeError) as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
return Response(
|
||||
|
||||
Reference in New Issue
Block a user