diff --git a/app/routers/ui.py b/app/routers/ui.py index 29aa4a8..b58b025 100644 --- a/app/routers/ui.py +++ b/app/routers/ui.py @@ -21,7 +21,7 @@ from app.models.todo import Todo from app.constants import COLORS, MATERIALS from app.filamentdb import available_colors, available_materials, get_stock from app.stl import get_stl_dir, list_stl_files -from app.stl_analysis import analyse, get_cache_map +from app.stl_analysis import analyse, get_cache_map # noqa: F401 used in job_detail route router = APIRouter() templates = Jinja2Templates(directory="app/templates") @@ -222,6 +222,18 @@ def job_detail(job_id: int, request: Request, db: Session = Depends(get_db)): }) +@router.post("/jobs/{job_id}/analyse") +def analyse_job_file(job_id: int, db: Session = Depends(get_db)): + from fastapi import HTTPException + job = db.query(PrintJob).filter(PrintJob.id == job_id).first() + if not job or not job.file_name: + raise HTTPException(status_code=404, detail="Job or file not found") + db.query(StlCache).filter_by(filename=job.file_name).delete() + db.commit() + analyse(job.file_name, db) + return RedirectResponse(url=f"/jobs/{job_id}", status_code=HTTP_303_SEE_OTHER) + + @router.post("/jobs/{job_id}/log") def add_job_log(job_id: int, message: str = Form(...), db: Session = Depends(get_db)): db.add(JobLog(job_id=job_id, message=message.strip())) diff --git a/app/templates/job_detail.html b/app/templates/job_detail.html index a0c0136..0b34cb6 100644 --- a/app/templates/job_detail.html +++ b/app/templates/job_detail.html @@ -70,8 +70,15 @@ {# ── STL geometry ── #}
Geometry not available for gcode files.
{% elif job.file_name %} -Not yet analysed — will be computed on next upload.
+Not yet analysed.
{% else %}No file attached.
{% endif %}