dev #60

Merged
sbcrumb merged 42 commits from dev into main 2025-10-22 21:27:04 -04:00
2 changed files with 83 additions and 27 deletions
Showing only changes of commit 4095ca18c8 - Show all commits
+77 -11
View File
@@ -1364,32 +1364,98 @@ def register_web_routes(app, dependencies):
@app.get("/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.error
import json
import os
import socket
import time
import subprocess
import re
from datetime import datetime, timedelta
# Get core container URL to check if it's responsive
core_host = os.environ.get("CORE_API_HOST", "nfoguard-core")
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 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"
req = urllib.request.Request(health_url)
with urllib.request.urlopen(req, timeout=5) as response:
# Core is responsive, return basic status
# TODO: Core container should implement proper scan status tracking
return {
"scanning": False,
"message": "Scan status tracking not fully implemented - check core container logs"
}
return {"scanning": False, "message": "No recent scan activity detected"}
except (urllib.error.URLError, socket.timeout):
return {"scanning": False, "message": "Core container unavailable"}
+6 -16
View File
@@ -118,8 +118,8 @@ async function loadDashboard() {
updateDashboardStats();
updateDashboardCharts();
// Note: Scan status tracking not implemented yet
// Real-time scan status would require core container modifications
// Check if there's an ongoing scan when dashboard loads
await checkScanStatus();
} catch (error) {
console.error('Failed to load dashboard:', error);
}
@@ -1443,13 +1443,8 @@ async function handleManualScan(event) {
showToast(`✅ Manual scan initiated: ${result.message}`, 'success');
// Show scan status banner temporarily
updateScanStatus('Manual scan started - check core container logs for progress', true);
// 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);
// Start polling for scan status with log-based detection
startScanStatusPolling();
} catch (error) {
console.error('Manual scan failed:', error);
@@ -1491,13 +1486,8 @@ async function handleCustomScan(event) {
showToast(`✅ Custom scan initiated: ${result.message}`, 'success');
// Show scan status banner temporarily
updateScanStatus('Custom directory scan started - check core container logs for progress', true);
// 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);
// Start polling for scan status with log-based detection
startScanStatusPolling();
} catch (error) {
console.error('Custom scan failed:', error);