Lists all processed projects found in the wiki cache directory. Projects are identified by files named like: deepwiki_cache_{repo_type}_{owner}_{repo}_{language}.json
()
| 576 | # --- Processed Projects Endpoint --- (New Endpoint) |
| 577 | @app.get("/api/processed_projects", response_model=List[ProcessedProjectEntry]) |
| 578 | async def get_processed_projects(): |
| 579 | """ |
| 580 | Lists all processed projects found in the wiki cache directory. |
| 581 | Projects are identified by files named like: deepwiki_cache_{repo_type}_{owner}_{repo}_{language}.json |
| 582 | """ |
| 583 | project_entries: List[ProcessedProjectEntry] = [] |
| 584 | # WIKI_CACHE_DIR is already defined globally in the file |
| 585 | |
| 586 | try: |
| 587 | if not os.path.exists(WIKI_CACHE_DIR): |
| 588 | logger.info(f"Cache directory {WIKI_CACHE_DIR} not found. Returning empty list.") |
| 589 | return [] |
| 590 | |
| 591 | logger.info(f"Scanning for project cache files in: {WIKI_CACHE_DIR}") |
| 592 | filenames = await asyncio.to_thread(os.listdir, WIKI_CACHE_DIR) # Use asyncio.to_thread for os.listdir |
| 593 | |
| 594 | for filename in filenames: |
| 595 | if filename.startswith("deepwiki_cache_") and filename.endswith(".json"): |
| 596 | file_path = os.path.join(WIKI_CACHE_DIR, filename) |
| 597 | try: |
| 598 | stats = await asyncio.to_thread(os.stat, file_path) # Use asyncio.to_thread for os.stat |
| 599 | parts = filename.replace("deepwiki_cache_", "").replace(".json", "").split('_') |
| 600 | |
| 601 | # Expecting repo_type_owner_repo_language |
| 602 | # Example: deepwiki_cache_github_AsyncFuncAI_deepwiki-open_en.json |
| 603 | # parts = [github, AsyncFuncAI, deepwiki-open, en] |
| 604 | if len(parts) >= 4: |
| 605 | repo_type = parts[0] |
| 606 | owner = parts[1] |
| 607 | language = parts[-1] # language is the last part |
| 608 | repo = "_".join(parts[2:-1]) # repo can contain underscores |
| 609 | |
| 610 | project_entries.append( |
| 611 | ProcessedProjectEntry( |
| 612 | id=filename, |
| 613 | owner=owner, |
| 614 | repo=repo, |
| 615 | name=f"{owner}/{repo}", |
| 616 | repo_type=repo_type, |
| 617 | submittedAt=int(stats.st_mtime * 1000), # Convert to milliseconds |
| 618 | language=language |
| 619 | ) |
| 620 | ) |
| 621 | else: |
| 622 | logger.warning(f"Could not parse project details from filename: {filename}") |
| 623 | except Exception as e: |
| 624 | logger.error(f"Error processing file {file_path}: {e}") |
| 625 | continue # Skip this file on error |
| 626 | |
| 627 | # Sort by most recent first |
| 628 | project_entries.sort(key=lambda p: p.submittedAt, reverse=True) |
| 629 | logger.info(f"Found {len(project_entries)} processed project entries.") |
| 630 | return project_entries |
| 631 | |
| 632 | except Exception as e: |
| 633 | logger.error(f"Error listing processed projects from {WIKI_CACHE_DIR}: {e}", exc_info=True) |
| 634 | raise HTTPException(status_code=500, detail="Failed to list processed projects from server cache.") |
nothing calls this directly
no test coverage detected