Files
Stefano a42d4c30a6
All checks were successful
AWS Deploy on Push / build (push) Successful in 5m18s
Started (incomplete) implementation of stream verification scheduler and endpoints
2025-06-17 17:12:39 -05:00

83 lines
2.0 KiB
Python

from fastapi import FastAPI
from fastapi.concurrency import asynccontextmanager
from fastapi.openapi.utils import get_openapi
from app.iptv.scheduler import StreamScheduler
from app.routers import auth, channels, groups, playlist, priorities, scheduler
from app.utils.database import init_db
@asynccontextmanager
async def lifespan(app: FastAPI):
# Initialize database tables on startup
init_db()
# Initialize and start the stream scheduler
scheduler = StreamScheduler(app)
app.state.scheduler = scheduler # Store scheduler in app state
scheduler.start()
yield
# Shutdown scheduler on app shutdown
scheduler.shutdown()
app = FastAPI(
lifespan=lifespan,
title="IPTV Manager API",
description="API for IPTV Manager service",
version="1.0.0",
)
def custom_openapi():
if app.openapi_schema:
return app.openapi_schema
openapi_schema = get_openapi(
title=app.title,
version=app.version,
description=app.description,
routes=app.routes,
)
# Ensure components object exists
if "components" not in openapi_schema:
openapi_schema["components"] = {}
# Add schemas if they don't exist
if "schemas" not in openapi_schema["components"]:
openapi_schema["components"]["schemas"] = {}
# Add security scheme component
openapi_schema["components"]["securitySchemes"] = {
"Bearer": {"type": "http", "scheme": "bearer", "bearerFormat": "JWT"}
}
# Add global security requirement
openapi_schema["security"] = [{"Bearer": []}]
# Set OpenAPI version explicitly
openapi_schema["openapi"] = "3.1.0"
app.openapi_schema = openapi_schema
return app.openapi_schema
app.openapi = custom_openapi
@app.get("/")
async def root():
return {"message": "IPTV Manager API"}
# Include routers
app.include_router(auth.router)
app.include_router(channels.router)
app.include_router(playlist.router)
app.include_router(priorities.router)
app.include_router(groups.router)
app.include_router(scheduler.router)