This commit is contained in:
+55
-31
@@ -11,14 +11,30 @@ from fastapi import FastAPI
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.responses import FileResponse
|
||||
|
||||
# Add web interface path for imports
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), "nfoguard-web"))
|
||||
# Import existing configuration (keep using core config for simplicity)
|
||||
from config.settings import config
|
||||
|
||||
# Import web-specific components
|
||||
from config.web_settings import web_config as config
|
||||
from core.web_database import WebDatabase
|
||||
from api.web_routes import register_web_routes
|
||||
from api.auth import SimpleAuthMiddleware, create_auth_dependencies
|
||||
# Import existing database and components
|
||||
from core.database import NFOGuardDatabase
|
||||
|
||||
# Add web interface path for routes only
|
||||
web_path = os.path.join(os.path.dirname(__file__), "nfoguard-web")
|
||||
if web_path not in sys.path:
|
||||
sys.path.append(web_path)
|
||||
|
||||
# Import web routes from separated system
|
||||
try:
|
||||
from api.web_routes import register_web_routes as register_separated_web_routes
|
||||
use_separated_routes = True
|
||||
print("✅ Using separated web routes with DELETE /api/episodes/ support")
|
||||
except ImportError:
|
||||
# Fallback to old routes if separated routes not available
|
||||
from api.web_routes import register_web_routes
|
||||
use_separated_routes = False
|
||||
print("⚠️ Using legacy web routes - DELETE functionality may be limited")
|
||||
|
||||
# Import authentication system
|
||||
from api.auth import SimpleAuthMiddleware, AuthSession
|
||||
|
||||
|
||||
def create_web_app() -> FastAPI:
|
||||
@@ -102,52 +118,60 @@ def main():
|
||||
"""Main entry point for NFOGuard Web Interface"""
|
||||
print("🌐 Starting NFOGuard Web Interface...")
|
||||
|
||||
# Use web config system
|
||||
web_host = config.web_host
|
||||
web_port = config.web_port
|
||||
# Use existing config system
|
||||
web_host = os.environ.get("WEB_HOST", "0.0.0.0")
|
||||
web_port = int(os.environ.get("WEB_PORT", "8081"))
|
||||
|
||||
print(f"📊 Configuration: Port {web_port}")
|
||||
|
||||
# Create FastAPI app
|
||||
app = create_web_app()
|
||||
|
||||
# Initialize web database (read-only optimized)
|
||||
# Initialize database using existing system
|
||||
try:
|
||||
db = WebDatabase(
|
||||
db_type=config.db_type,
|
||||
host=config.db_host,
|
||||
port=config.db_port,
|
||||
database=config.db_name,
|
||||
user=config.db_user,
|
||||
password=config.db_password
|
||||
)
|
||||
db = NFOGuardDatabase(config)
|
||||
print(f"✅ Connected to database: {config.db_host}:{config.db_port}/{config.db_name}")
|
||||
except Exception as e:
|
||||
print(f"❌ Failed to connect to database: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
# Setup authentication if enabled
|
||||
auth_enabled = getattr(config, 'web_auth_enabled', False)
|
||||
session_manager = None
|
||||
|
||||
if auth_enabled:
|
||||
session_timeout = getattr(config, 'web_auth_session_timeout', 3600)
|
||||
session_manager = AuthSession(timeout_seconds=session_timeout)
|
||||
print(f"🔐 Web authentication enabled (session timeout: {session_timeout}s)")
|
||||
else:
|
||||
print("🌐 Web authentication disabled")
|
||||
|
||||
# Create dependencies for dependency injection
|
||||
dependencies = {
|
||||
"db": db,
|
||||
"config": config
|
||||
"config": config,
|
||||
"nfo_manager": None, # Not needed for read-only web interface
|
||||
"movie_processor": None, # Not needed for read-only web interface
|
||||
"tv_processor": None, # Not needed for read-only web interface
|
||||
"auth_enabled": auth_enabled,
|
||||
"session_manager": session_manager
|
||||
}
|
||||
|
||||
# Add authentication dependencies if enabled
|
||||
if config.web_auth_enabled:
|
||||
auth_deps = create_auth_dependencies(config)
|
||||
dependencies.update(auth_deps)
|
||||
|
||||
# Add authentication middleware
|
||||
app.add_middleware(SimpleAuthMiddleware, config=config)
|
||||
print(f"🔐 Web authentication enabled for user: {config.web_auth_username}")
|
||||
else:
|
||||
print("🔓 Web authentication disabled - interface is public")
|
||||
# Add authentication middleware if enabled (BEFORE routes)
|
||||
if auth_enabled:
|
||||
app.add_middleware(SimpleAuthMiddleware, config=config, session_manager=session_manager)
|
||||
print("🔐 Authentication middleware added to web interface")
|
||||
|
||||
# Setup static files and routes
|
||||
setup_static_files(app)
|
||||
|
||||
# Register web routes
|
||||
# Register web routes (prefer separated routes if available)
|
||||
if use_separated_routes:
|
||||
register_separated_web_routes(app, dependencies)
|
||||
print("✅ Registered separated web routes with full /api/episodes/ support")
|
||||
else:
|
||||
register_web_routes(app, dependencies)
|
||||
print("⚠️ Using legacy web routes")
|
||||
|
||||
print(f"🚀 Starting web server on {web_host}:{web_port}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user