Files
manage/backend/dependencies.py
T
alex 3c432473e5 Add FastAPI backend and React frontend subprojects
Backend:
- FastAPI app with 17 REST endpoints covering dashboard, monitoring,
  media index, file browser, and jobs
- Reuses existing clients/domain/services unchanged
- pydantic-settings config, dependency injection, CORS setup
- Auto-generated OpenAPI docs at /docs

Frontend:
- Vite + React + TypeScript SPA
- @tanstack/react-query for data fetching with polling
- ag-grid-react for media table and file browser
- recharts for monitoring charts
- Tailwind CSS styling
- 4 pages: Dashboard, Monitoring, Media, File Browser
- Typed API client matching all backend endpoints

Also:
- docs/MIGRATION_PLAN.md with full architecture plan
- Updated .gitignore for both subprojects
- Streamlit app preserved for now (can coexist)
2026-04-30 21:40:18 +02:00

48 lines
1.4 KiB
Python

"""Dependency injection for FastAPI.
Provides singleton-like access to SSH and Jellyfin clients via FastAPI's
dependency system. Uses lru_cache so connections are reused across requests.
"""
from __future__ import annotations
from functools import lru_cache
from clients.jellyfin import JellyfinClient
from clients.ssh import RemoteSSHClient
from config import get_settings
@lru_cache
def get_jellyfin_client() -> JellyfinClient:
"""Return a cached Jellyfin client."""
settings = get_settings()
return JellyfinClient(settings.jellyfin.url, settings.jellyfin.api_key)
@lru_cache
def get_ssh_client() -> RemoteSSHClient:
"""Return a cached SSH client (connects on first use)."""
settings = get_settings()
client = RemoteSSHClient(
host=settings.ssh.host,
username=settings.ssh.username,
port=settings.ssh.port,
key_filename=settings.ssh.key_filename or None,
password=settings.ssh.password or None,
)
client.connect()
return client
def get_user_id() -> str:
"""Return the configured Jellyfin user ID, or discover the first available user."""
settings = get_settings()
if settings.jellyfin.user_id:
return settings.jellyfin.user_id
client = get_jellyfin_client()
users = client.users()
if not users:
raise RuntimeError("No Jellyfin users found and JELLYFIN_USER_ID not set")
return users[0]["Id"]