From 92136f05082775b1a5ea8573f55e4b8b0f66acf8 Mon Sep 17 00:00:00 2001 From: cottongin Date: Thu, 12 Mar 2026 07:19:01 -0400 Subject: [PATCH] Wire dashboard into app - Add web_user, web_password, secret_key as optional params to create_app - Conditionally mount dashboard router when all three are set - Pass settings from main.py to create_app - Add tests for no dashboard/login routes when config absent Made-with: Cursor --- src/ntr_fetcher/api.py | 19 +++++++++++++++++++ src/ntr_fetcher/main.py | 3 +++ tests/test_api.py | 10 ++++++++++ 3 files changed, 32 insertions(+) diff --git a/src/ntr_fetcher/api.py b/src/ntr_fetcher/api.py index 88924fa..d562522 100644 --- a/src/ntr_fetcher/api.py +++ b/src/ntr_fetcher/api.py @@ -29,6 +29,9 @@ def create_app( admin_token: str, show_day: int = 2, show_hour: int = 22, + web_user: str | None = None, + web_password: str | None = None, + secret_key: str | None = None, ) -> FastAPI: app = FastAPI(title="NtR SoundCloud Fetcher") @@ -147,4 +150,20 @@ def create_app( db.move_show_track(show.id, track_id, body.position) return {"status": "moved"} + if all([web_user, web_password, secret_key]): + from ntr_fetcher.dashboard import create_dashboard_router + from ntr_fetcher.websocket import AnnounceManager + manager = AnnounceManager() + dashboard_router = create_dashboard_router( + db=db, + manager=manager, + admin_token=admin_token, + web_user=web_user, + web_password=web_password, + secret_key=secret_key, + show_day=show_day, + show_hour=show_hour, + ) + app.include_router(dashboard_router) + return app diff --git a/src/ntr_fetcher/main.py b/src/ntr_fetcher/main.py index 3484926..05f5a38 100644 --- a/src/ntr_fetcher/main.py +++ b/src/ntr_fetcher/main.py @@ -80,6 +80,9 @@ def run() -> None: admin_token=settings.admin_token, show_day=settings.show_day, show_hour=settings.show_hour, + web_user=settings.web_user, + web_password=settings.web_password, + secret_key=settings.secret_key, ) @app.on_event("startup") diff --git a/tests/test_api.py b/tests/test_api.py index d8609bd..c766cf1 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -142,3 +142,13 @@ def test_show_by_episode(client, db): def test_show_by_episode_not_found(client): resp = client.get("/shows/by-episode/999") assert resp.status_code == 404 + + +def test_no_dashboard_routes_without_config(client): + resp = client.get("/dashboard", follow_redirects=False) + assert resp.status_code == 404 + + +def test_no_login_route_without_config(client): + resp = client.get("/login") + assert resp.status_code == 404