import asyncio from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from .config import settings from .db import init_db from .routers.requests import ( router as requests_router, startup_warmup_requests_cache, run_requests_delta_loop, run_daily_requests_full_sync, run_daily_db_cleanup, ) from .routers.auth import router as auth_router from .routers.admin import router as admin_router from .routers.images import router as images_router from .routers.branding import router as branding_router from .routers.status import router as status_router from .routers.feedback import router as feedback_router from .services.jellyfin_sync import run_daily_jellyfin_sync from .services.jellyseerr_sync import run_jellyseerr_sync_loop from .services.expiry import run_expiry_loop from .logging_config import configure_logging from .runtime import get_runtime_settings app = FastAPI(title=settings.app_name) app.add_middleware( CORSMiddleware, allow_origins=[settings.cors_allow_origin], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) @app.get("/health") async def health() -> dict: return {"status": "ok"} @app.on_event("startup") async def startup() -> None: init_db() runtime = get_runtime_settings() configure_logging(runtime.log_level, runtime.log_file) asyncio.create_task(run_daily_jellyfin_sync()) asyncio.create_task(run_jellyseerr_sync_loop()) asyncio.create_task(startup_warmup_requests_cache()) asyncio.create_task(run_requests_delta_loop()) asyncio.create_task(run_daily_requests_full_sync()) asyncio.create_task(run_daily_db_cleanup()) asyncio.create_task(run_expiry_loop()) app.include_router(requests_router) app.include_router(auth_router) app.include_router(admin_router) app.include_router(images_router) app.include_router(branding_router) app.include_router(status_router) app.include_router(feedback_router)