This commit is contained in:
+77
-11
@@ -1364,32 +1364,98 @@ def register_web_routes(app, dependencies):
|
|||||||
|
|
||||||
@app.get("/api/scan/status")
|
@app.get("/api/scan/status")
|
||||||
async def api_scan_status():
|
async def api_scan_status():
|
||||||
"""Check scan status by looking at core container logs"""
|
"""Check scan status by attempting to detect scan activity"""
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import urllib.error
|
import urllib.error
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
import time
|
import subprocess
|
||||||
|
import re
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
# Get core container URL to check if it's responsive
|
# Get core container URL to check if it's responsive
|
||||||
core_host = os.environ.get("CORE_API_HOST", "nfoguard-core")
|
core_host = os.environ.get("CORE_API_HOST", "nfoguard-core")
|
||||||
core_port = os.environ.get("CORE_API_PORT", "8080")
|
core_port = os.environ.get("CORE_API_PORT", "8080")
|
||||||
|
|
||||||
# For now, implement basic status tracking based on recent activity
|
|
||||||
# This is a simple implementation - ideally the core would track this
|
|
||||||
try:
|
try:
|
||||||
# Try to reach core container to see if it's active
|
# Try to get recent logs from core container to detect scanning activity
|
||||||
|
# This uses docker logs with timestamp filtering
|
||||||
|
result = subprocess.run([
|
||||||
|
'docker', 'logs', '--since', '30s', 'nfoguard-core'
|
||||||
|
], capture_output=True, text=True, timeout=5)
|
||||||
|
|
||||||
|
if result.returncode == 0:
|
||||||
|
logs = result.stdout
|
||||||
|
|
||||||
|
# Look for scan activity patterns
|
||||||
|
scan_patterns = [
|
||||||
|
r'Processing TV series: (.+?) \[imdb',
|
||||||
|
r'INFO: Scanning movies in: (.+)',
|
||||||
|
r'Processed (\d+) TV series',
|
||||||
|
r'MANUAL SCAN STARTED: (.+?) scan',
|
||||||
|
r'MANUAL SCAN COMPLETED: (.+?) scan'
|
||||||
|
]
|
||||||
|
|
||||||
|
current_activity = None
|
||||||
|
scan_active = False
|
||||||
|
series_count = 0
|
||||||
|
|
||||||
|
# Parse recent logs for activity
|
||||||
|
lines = logs.split('\n')
|
||||||
|
for line in reversed(lines[-50:]): # Check last 50 lines
|
||||||
|
# Check for completion
|
||||||
|
if 'MANUAL SCAN COMPLETED' in line:
|
||||||
|
break
|
||||||
|
|
||||||
|
# Check for start
|
||||||
|
if 'MANUAL SCAN STARTED' in line:
|
||||||
|
scan_active = True
|
||||||
|
match = re.search(r'MANUAL SCAN STARTED: (.+?) scan', line)
|
||||||
|
if match:
|
||||||
|
scan_type = match.group(1)
|
||||||
|
break
|
||||||
|
|
||||||
|
# Check for current processing
|
||||||
|
if 'Processing TV series:' in line:
|
||||||
|
match = re.search(r'Processing TV series: (.+?) \[imdb', line)
|
||||||
|
if match:
|
||||||
|
current_activity = f"Processing: {match.group(1)}"
|
||||||
|
scan_active = True
|
||||||
|
elif 'Scanning movies in:' in line:
|
||||||
|
match = re.search(r'Scanning movies in: (.+)', line)
|
||||||
|
if match:
|
||||||
|
current_activity = f"Scanning movies in: {match.group(1)}"
|
||||||
|
scan_active = True
|
||||||
|
elif 'Processed' in line and 'TV series' in line:
|
||||||
|
match = re.search(r'Processed (\d+) TV series', line)
|
||||||
|
if match:
|
||||||
|
series_count = int(match.group(1))
|
||||||
|
|
||||||
|
if scan_active and current_activity:
|
||||||
|
message = current_activity
|
||||||
|
if series_count > 0:
|
||||||
|
message += f" ({series_count} series processed)"
|
||||||
|
return {"scanning": True, "message": message}
|
||||||
|
elif scan_active:
|
||||||
|
return {"scanning": True, "message": "Scan in progress..."}
|
||||||
|
else:
|
||||||
|
return {"scanning": False, "message": "No scan detected"}
|
||||||
|
|
||||||
|
except subprocess.TimeoutExpired:
|
||||||
|
pass
|
||||||
|
except subprocess.SubprocessError:
|
||||||
|
pass
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Fallback to basic health check
|
||||||
|
try:
|
||||||
health_url = f"http://{core_host}:{core_port}/health"
|
health_url = f"http://{core_host}:{core_port}/health"
|
||||||
req = urllib.request.Request(health_url)
|
req = urllib.request.Request(health_url)
|
||||||
|
|
||||||
with urllib.request.urlopen(req, timeout=5) as response:
|
with urllib.request.urlopen(req, timeout=5) as response:
|
||||||
# Core is responsive, return basic status
|
return {"scanning": False, "message": "No recent scan activity detected"}
|
||||||
# TODO: Core container should implement proper scan status tracking
|
|
||||||
return {
|
|
||||||
"scanning": False,
|
|
||||||
"message": "Scan status tracking not fully implemented - check core container logs"
|
|
||||||
}
|
|
||||||
|
|
||||||
except (urllib.error.URLError, socket.timeout):
|
except (urllib.error.URLError, socket.timeout):
|
||||||
return {"scanning": False, "message": "Core container unavailable"}
|
return {"scanning": False, "message": "Core container unavailable"}
|
||||||
|
|||||||
@@ -118,8 +118,8 @@ async function loadDashboard() {
|
|||||||
updateDashboardStats();
|
updateDashboardStats();
|
||||||
updateDashboardCharts();
|
updateDashboardCharts();
|
||||||
|
|
||||||
// Note: Scan status tracking not implemented yet
|
// Check if there's an ongoing scan when dashboard loads
|
||||||
// Real-time scan status would require core container modifications
|
await checkScanStatus();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to load dashboard:', error);
|
console.error('Failed to load dashboard:', error);
|
||||||
}
|
}
|
||||||
@@ -1443,13 +1443,8 @@ async function handleManualScan(event) {
|
|||||||
|
|
||||||
showToast(`✅ Manual scan initiated: ${result.message}`, 'success');
|
showToast(`✅ Manual scan initiated: ${result.message}`, 'success');
|
||||||
|
|
||||||
// Show scan status banner temporarily
|
// Start polling for scan status with log-based detection
|
||||||
updateScanStatus('Manual scan started - check core container logs for progress', true);
|
startScanStatusPolling();
|
||||||
|
|
||||||
// Hide banner after 10 seconds since we don't have real-time tracking yet
|
|
||||||
setTimeout(() => {
|
|
||||||
updateScanStatus('Scan status tracking not available - check core container logs', false);
|
|
||||||
}, 10000);
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Manual scan failed:', error);
|
console.error('Manual scan failed:', error);
|
||||||
@@ -1491,13 +1486,8 @@ async function handleCustomScan(event) {
|
|||||||
|
|
||||||
showToast(`✅ Custom scan initiated: ${result.message}`, 'success');
|
showToast(`✅ Custom scan initiated: ${result.message}`, 'success');
|
||||||
|
|
||||||
// Show scan status banner temporarily
|
// Start polling for scan status with log-based detection
|
||||||
updateScanStatus('Custom directory scan started - check core container logs for progress', true);
|
startScanStatusPolling();
|
||||||
|
|
||||||
// Hide banner after 10 seconds since we don't have real-time tracking yet
|
|
||||||
setTimeout(() => {
|
|
||||||
updateScanStatus('Scan status tracking not available - check core container logs', false);
|
|
||||||
}, 10000);
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Custom scan failed:', error);
|
console.error('Custom scan failed:', error);
|
||||||
|
|||||||
Reference in New Issue
Block a user