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
This commit is contained in:
cottongin
2026-03-12 07:19:01 -04:00
parent e90f44439b
commit 92136f0508
3 changed files with 32 additions and 0 deletions

View File

@@ -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

View File

@@ -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")

View File

@@ -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