diff --git a/docs/instructions.md b/docs/instructions.md index e5e784b..7747247 100644 --- a/docs/instructions.md +++ b/docs/instructions.md @@ -297,15 +297,15 @@ For each task completed: - **What**: Checking for poster.jpg, logo.png, fanart.jpg existence - **Fix**: ✅ Created `src/server/utils/media.py` utility module - **Status**: COMPLETED (January 24, 2026) -- **Resolution**: - - Created comprehensive media utilities module with functions: - - `check_media_files()`: Check existence of standard media files - - `get_media_file_paths()`: Get paths to existing media files - - `has_all_images()`: Check for complete image set - - `count_video_files()` / `has_video_files()`: Video file utilities - - Constants: `POSTER_FILENAME`, `LOGO_FILENAME`, `FANART_FILENAME`, `NFO_FILENAME`, `VIDEO_EXTENSIONS` - - Updated 7 duplicate locations in `nfo.py` and `background_loader_service.py` - - Functions accept both `str` and `Path` for compatibility +- **Resolution**: + - Created comprehensive media utilities module with functions: + - `check_media_files()`: Check existence of standard media files + - `get_media_file_paths()`: Get paths to existing media files + - `has_all_images()`: Check for complete image set + - `count_video_files()` / `has_video_files()`: Video file utilities + - Constants: `POSTER_FILENAME`, `LOGO_FILENAME`, `FANART_FILENAME`, `NFO_FILENAME`, `VIDEO_EXTENSIONS` + - Updated 7 duplicate locations in `nfo.py` and `background_loader_service.py` + - Functions accept both `str` and `Path` for compatibility ### Further Considerations (Require Architecture Decisions) diff --git a/src/server/utils/dependencies.py b/src/server/utils/dependencies.py index 4e2604e..e1a88a5 100644 --- a/src/server/utils/dependencies.py +++ b/src/server/utils/dependencies.py @@ -165,21 +165,21 @@ async def get_optional_database_session() -> AsyncGenerator: """ try: from src.server.database import get_db_session + + # Try to get a session - if database not initialized, this will raise RuntimeError + async with get_db_session() as session: + try: + yield session + # Auto-commit on successful completion + await session.commit() + except Exception: + # Auto-rollback on error + await session.rollback() + raise except (ImportError, RuntimeError): - # Database not available - yield None + # Database not available or not initialized - yield None yield None return - - # Use get_db_session context manager properly - async with get_db_session() as session: - try: - yield session - # Auto-commit on successful completion - await session.commit() - except Exception: - # Auto-rollback on error - await session.rollback() - raise def get_current_user( diff --git a/src/server/utils/media.py b/src/server/utils/media.py index 1ad205a..fde265e 100644 --- a/src/server/utils/media.py +++ b/src/server/utils/media.py @@ -7,7 +7,6 @@ This module provides utilities for checking and validating media files from pathlib import Path from typing import Dict, Optional, Union - # Standard media file names as defined by Kodi/Plex conventions POSTER_FILENAME = "poster.jpg" LOGO_FILENAME = "logo.png"