Spaces:
Sleeping
Sleeping
Commit
·
712a66b
1
Parent(s):
a96851e
Auto-commit: app.py updated
Browse files
app.py
CHANGED
|
@@ -496,6 +496,26 @@ async def execute(request: Request):
|
|
| 496 |
return JSONResponse(result)
|
| 497 |
|
| 498 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 499 |
@app.get("/health")
|
| 500 |
async def health():
|
| 501 |
"""Health check endpoint"""
|
|
|
|
| 496 |
return JSONResponse(result)
|
| 497 |
|
| 498 |
|
| 499 |
+
@app.get("/preview/{preview_id}")
|
| 500 |
+
async def get_preview(preview_id: str):
|
| 501 |
+
"""
|
| 502 |
+
Get live preview of executed code
|
| 503 |
+
AI agents can GET this URL to view the rendered frontend
|
| 504 |
+
"""
|
| 505 |
+
# Clean expired previews
|
| 506 |
+
now = datetime.now()
|
| 507 |
+
expired_keys = [k for k, v in PREVIEW_STORAGE.items() if now - v["created"] > PREVIEW_EXPIRY]
|
| 508 |
+
for key in expired_keys:
|
| 509 |
+
del PREVIEW_STORAGE[key]
|
| 510 |
+
|
| 511 |
+
# Return preview
|
| 512 |
+
preview = PREVIEW_STORAGE.get(preview_id)
|
| 513 |
+
if not preview:
|
| 514 |
+
return HTMLResponse("<h1>Preview not found or expired</h1><p>Previews expire after 1 hour.</p>", status_code=404)
|
| 515 |
+
|
| 516 |
+
return HTMLResponse(preview["html"])
|
| 517 |
+
|
| 518 |
+
|
| 519 |
@app.get("/health")
|
| 520 |
async def health():
|
| 521 |
"""Health check endpoint"""
|