Implemented full JWT-based authentication integration between frontend and backend:
Frontend Changes:
- Updated login.html to store JWT tokens in localStorage after successful login
- Updated setup.html to use correct API payload format (master_password)
- Modified app.js and queue.js to include Bearer tokens in all authenticated requests
- Updated makeAuthenticatedRequest() to add Authorization header with JWT token
- Enhanced checkAuthentication() to verify token and redirect on 401 responses
- Updated logout() to clear tokens from localStorage
API Endpoint Updates:
- Mapped queue API endpoints to new backend structure
- /api/queue/clear → /api/queue/completed (DELETE) for clearing completed
- /api/queue/remove → /api/queue/{item_id} (DELETE) for single removal
- /api/queue/retry payload changed to {item_ids: []} array format
- /api/download/pause|resume|cancel → /api/queue/pause|resume|stop
Testing:
- Created test_frontend_integration_smoke.py with JWT token validation tests
- Verified login returns access_token, token_type, and expires_at
- Tested Bearer token authentication on protected endpoints
- Smoke tests passing for authentication flow
Documentation:
- Updated infrastructure.md with JWT authentication implementation details
- Documented token storage, API endpoint changes, and response formats
- Marked Frontend Integration task as completed in instructions.md
- Added frontend integration testing section
WebSocket:
- Verified WebSocket integration with new backend (already functional)
- Dual event handlers support both old and new message types
- Room-based subscriptions working correctly
This completes Task 7: Frontend Integration from the development instructions.
- Created websocket_client.js: Native WebSocket wrapper with Socket.IO-compatible interface
- Automatic reconnection with exponential backoff
- Room-based subscriptions for targeted updates
- Message queueing during disconnection
- Updated HTML templates (index.html, queue.html):
- Replaced Socket.IO CDN with native websocket_client.js
- No external dependencies needed
- Updated JavaScript files (app.js, queue.js):
- Added room subscriptions on WebSocket connect (scan_progress, download_progress, downloads)
- Added dual event handlers for backward compatibility
- Support both old (scan_completed) and new (scan_complete) message types
- Support both old (download_error) and new (download_failed) message types
- Support both old (queue_updated) and new (queue_status) message types
- Registered anime router in fastapi_app.py:
- Added anime_router import and registration
- All API routers now properly included
- Documentation:
- Created FRONTEND_INTEGRATION.md with comprehensive integration guide
- Updated infrastructure.md with frontend integration section
- Updated instructions.md to mark task as completed
- Testing:
- Verified anime endpoint tests pass (pytest)
- API endpoint mapping documented
- WebSocket message format changes documented
Benefits:
- Native WebSocket API (faster, smaller footprint)
- No external CDN dependencies
- Full backward compatibility with existing code
- Proper integration with backend services
- Real-time updates via room-based messaging
- Add comprehensive REST API for download queue management
- Implement GET /api/queue/status endpoint with queue status and statistics
- Implement POST /api/queue/add for adding episodes to queue with priority support
- Implement DELETE /api/queue/{id} and DELETE /api/queue/ for removing items
- Implement POST /api/queue/start and /api/queue/stop for queue control
- Implement POST /api/queue/pause and /api/queue/resume for pause/resume
- Implement POST /api/queue/reorder for queue item reordering
- Implement DELETE /api/queue/completed for clearing completed items
- Implement POST /api/queue/retry for retrying failed downloads
- Add get_download_service and get_anime_service dependencies
- Register download router in FastAPI application
- Add comprehensive test suite for all endpoints
- All endpoints require JWT authentication
- Update infrastructure documentation
- Remove completed task from instructions.md
Follows REST conventions with proper error handling and status codes.
Tests cover success cases, error conditions, and authentication requirements.
- Add comprehensive download queue models in src/server/models/download.py
- DownloadStatus and DownloadPriority enums for type safety
- EpisodeIdentifier for episode references
- DownloadProgress for real-time progress tracking
- DownloadItem for queue item representation with timestamps and error handling
- QueueStatus for overall queue state management
- QueueStats for aggregated queue statistics
- DownloadRequest/DownloadResponse for API contracts
- QueueOperationRequest and QueueReorderRequest for queue management
- QueueStatusResponse for complete status endpoint responses
- Add comprehensive unit tests (47 tests, all passing)
- Test validation constraints (positive numbers, ranges, etc.)
- Test default values and optional fields
- Test serialization/deserialization
- Test model relationships and nested structures
- Update documentation
- Add download models section to infrastructure.md
- Remove completed task from instructions.md
- Update models package __init__.py
All models follow PEP 8 style guide with proper type hints and validation.
- Enhanced existing src/server/utils/dependencies.py with optional SQLAlchemy import
- Added comprehensive unit tests in tests/unit/test_dependencies.py
- Created pytest configuration with asyncio support
- Implemented SeriesApp singleton dependency with proper error handling
- Added placeholders for database session and authentication dependencies
- Updated infrastructure.md with dependency injection documentation
- Completed dependency injection task from instructions.md
Features implemented:
- SeriesApp dependency with lazy initialization and singleton pattern
- Configuration validation for anime directory
- Comprehensive error handling for initialization failures
- Common query parameters for pagination
- Placeholder dependencies for future authentication and database features
- 18 passing unit tests covering all dependency injection scenarios
- Fix setup.html to use redirect_url from API response instead of hardcoded '/'
- Add database creation (aniworld.db, cache.db) during setup process
- Setup now properly creates all required files for validation
- After setup completion, users are correctly redirected to /login
- Tested: setup API returns correct redirect_url, database files created, redirect works
- Replace Flask url_for() with direct /static/ paths in all HTML templates
- Update CSS and JavaScript file references to use FastAPI static mount
- Convert Flask-specific template patterns to FastAPI-compatible syntax
- Update JavaScript API endpoints to match new FastAPI route structure:
* /api/series -> /api/v1/anime
* /api/search -> /api/v1/anime/search
* /api/rescan -> /api/v1/anime/rescan
- Add web interface routes for serving HTML templates
- Add template response endpoints for /app, /login, /setup, /queue
- Mark HTML template and JavaScript migration tasks as completed
- Maintain Jinja2 template compatibility with FastAPI
- Create detailed Pydantic models for anime requests and responses
- Add AnimeCreateRequest, AnimeUpdateRequest, PaginatedAnimeResponse, etc.
- Update route signatures to use proper response models
- Convert return values to use Pydantic models instead of raw dicts
- Configure Jinja2Templates in FastAPI application
- Mount StaticFiles for CSS, JS, images at /static endpoint
- Update anime search and list endpoints to use typed responses
- Mark completed Pydantic models and template configuration tasks in web_todo.md
- Convert Flask Blueprint to FastAPI router
- Replace @app.route() with FastAPI route decorators (@router.get, @router.post)
- Update route parameter syntax from <int:id> to {id: int} format
- Convert Flask request object usage to FastAPI Query/Depends parameters
- Update response handling to return dicts instead of Flask jsonify()
- Integrate SeriesApp as business logic layer for anime operations
- Add anime list, search, and rescan endpoints using SeriesApp
- Include anime router in main FastAPI application
- Mark route conversion tasks as completed in web_todo.md