Cyber Catalyst Team commited on
Commit
24e5442
·
1 Parent(s): e2e79bf

feat: add GET /api/workspace/latest-screenshot endpoint

Browse files
Files changed (1) hide show
  1. backend.py +24 -0
backend.py CHANGED
@@ -1027,6 +1027,30 @@ async def get_workspace_file(path: str):
1027
  raise HTTPException(status_code=500, detail=str(e))
1028
 
1029
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1030
  # ---------------------------------------------------------------------------
1031
  # Dashboard and Status API
1032
  # ---------------------------------------------------------------------------
 
1027
  raise HTTPException(status_code=500, detail=str(e))
1028
 
1029
 
1030
+ @app.get("/api/workspace/latest-screenshot")
1031
+ async def get_latest_screenshot():
1032
+ try:
1033
+ w_path = Path(WORKSPACE_DIR).resolve()
1034
+ png_files = []
1035
+ for p in w_path.rglob("*.png"):
1036
+ if any(part.startswith(".") for part in p.parts):
1037
+ continue
1038
+ try:
1039
+ mtime = p.stat().st_mtime
1040
+ png_files.append((p, mtime))
1041
+ except Exception:
1042
+ pass
1043
+ if not png_files:
1044
+ raise HTTPException(status_code=404, detail="No screenshot found")
1045
+ newest = max(png_files, key=lambda x: x[1])[0]
1046
+ from fastapi.responses import FileResponse
1047
+ return FileResponse(str(newest))
1048
+ except HTTPException as he:
1049
+ raise he
1050
+ except Exception as e:
1051
+ raise HTTPException(status_code=500, detail=str(e))
1052
+
1053
+
1054
  # ---------------------------------------------------------------------------
1055
  # Dashboard and Status API
1056
  # ---------------------------------------------------------------------------