This commit is contained in:
+55
-31
@@ -11,14 +11,30 @@ from fastapi import FastAPI
|
|||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
from fastapi.responses import FileResponse
|
from fastapi.responses import FileResponse
|
||||||
|
|
||||||
# Add web interface path for imports
|
# Import existing configuration (keep using core config for simplicity)
|
||||||
sys.path.append(os.path.join(os.path.dirname(__file__), "nfoguard-web"))
|
from config.settings import config
|
||||||
|
|
||||||
# Import web-specific components
|
# Import existing database and components
|
||||||
from config.web_settings import web_config as config
|
from core.database import NFOGuardDatabase
|
||||||
from core.web_database import WebDatabase
|
|
||||||
from api.web_routes import register_web_routes
|
# Add web interface path for routes only
|
||||||
from api.auth import SimpleAuthMiddleware, create_auth_dependencies
|
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:
|
def create_web_app() -> FastAPI:
|
||||||
@@ -102,52 +118,60 @@ def main():
|
|||||||
"""Main entry point for NFOGuard Web Interface"""
|
"""Main entry point for NFOGuard Web Interface"""
|
||||||
print("🌐 Starting NFOGuard Web Interface...")
|
print("🌐 Starting NFOGuard Web Interface...")
|
||||||
|
|
||||||
# Use web config system
|
# Use existing config system
|
||||||
web_host = config.web_host
|
web_host = os.environ.get("WEB_HOST", "0.0.0.0")
|
||||||
web_port = config.web_port
|
web_port = int(os.environ.get("WEB_PORT", "8081"))
|
||||||
|
|
||||||
print(f"📊 Configuration: Port {web_port}")
|
print(f"📊 Configuration: Port {web_port}")
|
||||||
|
|
||||||
# Create FastAPI app
|
# Create FastAPI app
|
||||||
app = create_web_app()
|
app = create_web_app()
|
||||||
|
|
||||||
# Initialize web database (read-only optimized)
|
# Initialize database using existing system
|
||||||
try:
|
try:
|
||||||
db = WebDatabase(
|
db = NFOGuardDatabase(config)
|
||||||
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
|
|
||||||
)
|
|
||||||
print(f"✅ Connected to database: {config.db_host}:{config.db_port}/{config.db_name}")
|
print(f"✅ Connected to database: {config.db_host}:{config.db_port}/{config.db_name}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"❌ Failed to connect to database: {e}")
|
print(f"❌ Failed to connect to database: {e}")
|
||||||
sys.exit(1)
|
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
|
# Create dependencies for dependency injection
|
||||||
dependencies = {
|
dependencies = {
|
||||||
"db": db,
|
"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
|
# Add authentication middleware if enabled (BEFORE routes)
|
||||||
if config.web_auth_enabled:
|
if auth_enabled:
|
||||||
auth_deps = create_auth_dependencies(config)
|
app.add_middleware(SimpleAuthMiddleware, config=config, session_manager=session_manager)
|
||||||
dependencies.update(auth_deps)
|
print("🔐 Authentication middleware added to web interface")
|
||||||
|
|
||||||
# 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")
|
|
||||||
|
|
||||||
# Setup static files and routes
|
# Setup static files and routes
|
||||||
setup_static_files(app)
|
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)
|
register_web_routes(app, dependencies)
|
||||||
|
print("⚠️ Using legacy web routes")
|
||||||
|
|
||||||
print(f"🚀 Starting web server on {web_host}:{web_port}")
|
print(f"🚀 Starting web server on {web_host}:{web_port}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user