fix duplication run

This commit is contained in:
2025-09-29 14:19:29 +02:00
parent 423b77033c
commit 3ab4467423
4 changed files with 148 additions and 37 deletions

View File

@@ -84,6 +84,22 @@ def init_series_app():
series_app = SeriesApp(directory_to_search)
return series_app
def get_series_app():
"""Get the current series app instance, initializing if needed."""
global series_app
if series_app is None:
# Try to get it from the main app module first
try:
import app
if hasattr(app, 'series_app') and app.series_app is not None:
series_app = app.series_app
return series_app
except ImportError:
pass
# If not available, initialize it
init_series_app()
return series_app
# Import socketio instance - this will need to be passed from app.py
socketio = None
@@ -131,7 +147,8 @@ def update_directory():
def get_series():
"""Get all series data."""
try:
if series_app is None or series_app.List is None:
current_series_app = get_series_app()
if current_series_app is None or current_series_app.List is None:
return jsonify({
'status': 'success',
'series': [],
@@ -141,7 +158,7 @@ def get_series():
# Get series data
series_data = []
for serie in series_app.List.GetList():
for serie in current_series_app.List.GetList():
series_data.append({
'folder': serie.folder,
'name': serie.name or serie.folder,
@@ -192,14 +209,15 @@ def search_series():
}), 400
# Check if series_app is available
if series_app is None:
current_series_app = get_series_app()
if current_series_app is None:
return jsonify({
'status': 'error',
'message': 'Series application not initialized'
}), 500
# Perform the search
search_results = series_app.search(query)
search_results = current_series_app.search(query)
# Format results for the frontend
results = []
@@ -819,9 +837,10 @@ def process_locks_status():
}
})
# Initialize the series app when the blueprint is loaded
try:
init_series_app()
except Exception as e:
print(f"Failed to initialize series app in API blueprint: {e}")
series_app = None
# Initialize the series app when needed (now handled in main app.py)
# Commenting out module-level initialization to prevent duplicate initialization
# try:
# init_series_app()
# except Exception as e:
# print(f"Failed to initialize series app in API blueprint: {e}")
# series_app = None