Spaces:
Running
Running
Commit ·
136b9b9
1
Parent(s): 7e44512
added packages details and programs details page
Browse files
main.py
CHANGED
|
@@ -439,6 +439,61 @@ def get_scroll_repos(
|
|
| 439 |
|
| 440 |
return [row_to_repo_dict(row) for row in rows]
|
| 441 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 442 |
|
| 443 |
def parse_repo_id(repo_id: str) -> tuple[str, str]:
|
| 444 |
"""Parse repo_id into owner and repo name.
|
|
@@ -634,22 +689,37 @@ async def search_programs_endpoint(
|
|
| 634 |
return search_repos(db_conn, q, search_type="program", limit=limit)
|
| 635 |
|
| 636 |
|
| 637 |
-
@app.get("/
|
| 638 |
-
async def
|
| 639 |
-
|
| 640 |
-
|
| 641 |
-
|
|
|
|
| 642 |
check_db_connection()
|
| 643 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 644 |
|
| 645 |
|
| 646 |
-
@app.get("/
|
| 647 |
-
async def
|
| 648 |
-
|
| 649 |
-
|
| 650 |
-
|
|
|
|
| 651 |
check_db_connection()
|
| 652 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 653 |
|
| 654 |
|
| 655 |
@app.get("/packages/scroll", tags=["Packages"])
|
|
|
|
| 439 |
|
| 440 |
return [row_to_repo_dict(row) for row in rows]
|
| 441 |
|
| 442 |
+
def get_section_repos(conn, section_name: str, limit: int = 50) -> List[Dict[str, Any]]:
|
| 443 |
+
"""Get repositories for a specific index section.
|
| 444 |
+
|
| 445 |
+
Args:
|
| 446 |
+
conn: Database connection
|
| 447 |
+
section_name: Name of the section (e.g., 'games', 'gui', 'web')
|
| 448 |
+
limit: Maximum number of results to return
|
| 449 |
+
|
| 450 |
+
Returns:
|
| 451 |
+
List of repository dictionaries
|
| 452 |
+
"""
|
| 453 |
+
sql = f"""
|
| 454 |
+
WITH section_repos AS (
|
| 455 |
+
SELECT repo_id FROM index_sections WHERE section_name = ?1
|
| 456 |
+
),
|
| 457 |
+
repo_data AS (
|
| 458 |
+
SELECT
|
| 459 |
+
r.id,
|
| 460 |
+
r.avatar_id,
|
| 461 |
+
r.owner,
|
| 462 |
+
r.platform,
|
| 463 |
+
r.description,
|
| 464 |
+
r.issues_count,
|
| 465 |
+
r.default_branch_name,
|
| 466 |
+
r.fork_count,
|
| 467 |
+
r.stargazer_count,
|
| 468 |
+
r.watchers_count,
|
| 469 |
+
r.pushed_at,
|
| 470 |
+
r.created_at,
|
| 471 |
+
r.is_archived,
|
| 472 |
+
r.is_disabled,
|
| 473 |
+
r.is_fork,
|
| 474 |
+
r.license,
|
| 475 |
+
r.primary_language,
|
| 476 |
+
r.minimum_zig_version
|
| 477 |
+
FROM repos r
|
| 478 |
+
JOIN section_repos sr ON r.id = sr.repo_id
|
| 479 |
+
LEFT JOIN packages pkg ON r.id = pkg.repo_id
|
| 480 |
+
LEFT JOIN programs prog ON r.id = prog.repo_id
|
| 481 |
+
WHERE
|
| 482 |
+
r.is_disabled = 0
|
| 483 |
+
AND (pkg.repo_id IS NOT NULL OR prog.repo_id IS NOT NULL)
|
| 484 |
+
LIMIT ?2
|
| 485 |
+
)
|
| 486 |
+
SELECT
|
| 487 |
+
rd.*,
|
| 488 |
+
(SELECT COUNT(*) FROM repo_dependents WHERE repo_id = rd.id) as dependents_count
|
| 489 |
+
FROM repo_data rd
|
| 490 |
+
"""
|
| 491 |
+
|
| 492 |
+
cursor = conn.execute(sql, (section_name, limit))
|
| 493 |
+
rows = cursor.fetchall()
|
| 494 |
+
|
| 495 |
+
return [row_to_repo_dict(row) for row in rows]
|
| 496 |
+
|
| 497 |
|
| 498 |
def parse_repo_id(repo_id: str) -> tuple[str, str]:
|
| 499 |
"""Parse repo_id into owner and repo name.
|
|
|
|
| 689 |
return search_repos(db_conn, q, search_type="program", limit=limit)
|
| 690 |
|
| 691 |
|
| 692 |
+
@app.get("/packageIndexDetails", tags=["Packages"])
|
| 693 |
+
async def get_package_index_details_endpoint():
|
| 694 |
+
"""
|
| 695 |
+
Get all data required for the package index page.
|
| 696 |
+
Includes top 10 latest packages, top 10 most used packages, and curated sections.
|
| 697 |
+
"""
|
| 698 |
check_db_connection()
|
| 699 |
+
return {
|
| 700 |
+
"latest": get_latest_repos(db_conn, search_type="package", limit=10),
|
| 701 |
+
"most_used": get_scroll_repos(
|
| 702 |
+
db_conn, search_type="package", per_page=10, page=1
|
| 703 |
+
),
|
| 704 |
+
"games": get_section_repos(db_conn, "games", limit=50),
|
| 705 |
+
"gui": get_section_repos(db_conn, "gui", limit=50),
|
| 706 |
+
"web": get_section_repos(db_conn, "web", limit=50),
|
| 707 |
+
}
|
| 708 |
|
| 709 |
|
| 710 |
+
@app.get("/programIndexDetails", tags=["Programs"])
|
| 711 |
+
async def get_program_index_details_endpoint():
|
| 712 |
+
"""
|
| 713 |
+
Get all data required for the program index page.
|
| 714 |
+
Includes top 10 latest programs and top 10 most used programs.
|
| 715 |
+
"""
|
| 716 |
check_db_connection()
|
| 717 |
+
return {
|
| 718 |
+
"latest": get_latest_repos(db_conn, search_type="program", limit=10),
|
| 719 |
+
"most_used": get_scroll_repos(
|
| 720 |
+
db_conn, search_type="program", per_page=10, page=1
|
| 721 |
+
),
|
| 722 |
+
}
|
| 723 |
|
| 724 |
|
| 725 |
@app.get("/packages/scroll", tags=["Packages"])
|