Files
gcontext/api/app/routes_admin.py
T
bernatsamperaandClaude Opus 4.6 ce6e7711af Strip API to install-counter service, add CLI install ping
API: replace the marketplace (submit/approve/reject/moderation) with a
minimal counter table (id + downloads). Single upsert endpoint auto-creates
rows on first ping, X-Source: site exclusion preserved. Inline migration
copies existing counts and drops legacy tables. Removes slowapi, pyyaml,
manifest validation, and all moderation routes.

CLI: gcontext add now pings the API after a successful registry install so
the download counter reflects real usage. Fire-and-forget with 3s timeout,
gated to skip when GCONTEXT_REGISTRY is overridden (tests, private registries).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-08-11 00:12:09 +02:00

27 lines
830 B
Python

from fastapi import APIRouter, Depends, Header, HTTPException
from sqlalchemy import select
from sqlalchemy.orm import Session
from . import settings
from .db import get_session
from .models import Workflow
from .schemas import WorkflowOut
def require_admin(authorization: str = Header(default="")):
if authorization != f"Bearer {settings.admin_token()}":
raise HTTPException(status_code=401, detail="invalid admin token")
router = APIRouter(
prefix="/api/admin", tags=["admin"], dependencies=[Depends(require_admin)]
)
@router.get("/workflows", response_model=list[WorkflowOut])
def list_all(session: Session = Depends(get_session)):
rows = session.scalars(
select(Workflow).order_by(Workflow.downloads.desc())
).all()
return [WorkflowOut(id=w.id, downloads=w.downloads) for w in rows]