diff --git a/web/app.py b/web/app.py index f73bd49..c7bc1b7 100644 --- a/web/app.py +++ b/web/app.py @@ -167,11 +167,12 @@ async def dashboard(request: Request, username: str = Depends(get_current_admin) return templates.TemplateResponse(request=request, name="dashboard.html", context={ "username": username, - "stats": { - "users": users_count, "verified": verified_count, - "messages": messages_count, "ads": active_ads, - "polls": active_polls, "events": upcoming_events - }, + "users_count": users_count, + "verified_count": verified_count, + "messages_count": messages_count, + "active_ads": active_ads, + "active_polls": active_polls, + "upcoming_events": upcoming_events, "pending_count": pending_count }) @@ -728,6 +729,23 @@ async def api_emails_sync_ai(username: str = Depends(get_current_admin)): except Exception as e: return JSONResponse(status_code=500, content={"message": str(e)}) +@app.get("/api/emails/pipeline_status") +async def api_emails_pipeline_status(username: str = Depends(get_current_admin)): + import time + status_file = Path("/home/matrixhasyou/mutt/pipeline_status.json") + if not status_file.exists(): + return JSONResponse(content={"status": "idle", "step": "Неактивен", "updated_at": "-", "new_emails": 0, "total_emails": 0, "pdf_size_mb": 0.0}) + try: + with open(status_file) as f: + data = json.load(f) + mtime = status_file.stat().st_mtime + if data.get("status") == "running" and (time.time() - mtime > 600): + data["status"] = "stuck" + data["step"] = "Процесс завис или был остановлен" + return JSONResponse(content=data) + except Exception as e: + return JSONResponse(content={"status": "error", "message": str(e)}) + @app.get("/infra", response_class=HTMLResponse) async def get_infra_page(request: Request, username: str = Depends(get_current_admin)): async with AsyncSessionLocal() as session: diff --git a/web/templates/dashboard.html b/web/templates/dashboard.html index 38db077..b0cc514 100644 --- a/web/templates/dashboard.html +++ b/web/templates/dashboard.html @@ -67,7 +67,7 @@