MCPcopy Create free account
hub / github.com/HKUDS/Paper2Slides / get_status

Function get_status

api/server.py:551–643  ·  view source on GitHub ↗

Get processing status for a session

(session_id: str)

Source from the content-addressed store, hash-verified

549
550@app.get("/api/status/{session_id}")
551async def get_status(session_id: str):
552 """Get processing status for a session"""
553 try:
554 # Find the output directory for this session
555 session_dir = UPLOAD_DIR / session_id
556 if not session_dir.exists():
557 raise HTTPException(status_code=404, detail=f"Session {session_id} not found")
558
559 # Get PDF files from session
560 pdf_files = list(session_dir.glob("*.pdf"))
561 if not pdf_files:
562 return {"session_id": session_id, "status": "no_files", "stages": {}}
563
564 # Determine project name and paths
565 if len(pdf_files) > 1:
566 project_name = f"session_{session_id[:8]}"
567 else:
568 project_name = get_project_name(str(pdf_files[0]))
569
570 # Try to find the state file matching session_id
571 from paper2slides.core.paths import get_base_dir
572 import json
573
574 # Check both paper and general content types
575 state_data = None
576 most_recent_time = None
577
578 for content_type in ["paper", "general"]:
579 base_dir = Path(get_base_dir(str(OUTPUT_DIR), project_name, content_type))
580 if base_dir.exists():
581 # Look for all state.json files in config directories
582 for state_file_path in base_dir.rglob("state.json"):
583 if state_file_path.is_file():
584 try:
585 with open(state_file_path, 'r') as f:
586 current_state = json.load(f)
587
588 # First priority: exact match by session_id
589 if current_state.get("session_id") == session_id:
590 state_data = current_state
591 logger.debug(f"Found exact session match: {state_file_path}")
592 break
593
594 # Second priority: most recently updated (fallback for old state files)
595 updated_at = current_state.get("updated_at") or current_state.get("created_at")
596 if updated_at:
597 if most_recent_time is None or updated_at > most_recent_time:
598 most_recent_time = updated_at
599 # Only use as fallback if no exact match found
600 if state_data is None or state_data.get("session_id") != session_id:
601 state_data = current_state
602 except Exception as e:
603 logger.warning(f"Error reading state file {state_file_path}: {e}")
604 continue
605
606 # If found exact match, stop searching
607 if state_data and state_data.get("session_id") == session_id:
608 break

Callers

nothing calls this directly

Calls 2

get_project_nameFunction · 0.90
get_base_dirFunction · 0.90

Tested by

no test coverage detected