from fastapi import FastAPI from fastapi import HTTPException from starlette.concurrency import run_in_threadpool from app.inspection import InspectionError, UnsafeUrlError, inspect_url from app.models import InspectionRequest, InspectionResponse app = FastAPI( title="Media Ingest", description="Private broadcast media-ingest service.", version="0.1.0", ) @app.get("/", tags=["system"]) def root() -> dict[str, str]: return {"name": "Media Ingest", "status": "running"} @app.get("/health", tags=["system"]) def health() -> dict[str, str]: """Report whether the application process can serve requests.""" return {"status": "healthy"} @app.post("/api/inspect", response_model=InspectionResponse, tags=["inspection"]) async def inspect_source(request: InspectionRequest) -> dict[str, object]: """Inspect a public video URL without downloading media.""" try: return await run_in_threadpool(inspect_url, request.url) except UnsafeUrlError as error: raise HTTPException(status_code=400, detail=str(error)) from error except InspectionError as error: raise HTTPException(status_code=422, detail=str(error)) from error