This commit is contained in:
@@ -76,6 +76,7 @@ function initializeEventListeners() {
|
||||
// Forms
|
||||
document.getElementById('edit-form').addEventListener('submit', handleEditSubmit);
|
||||
document.getElementById('bulk-update-form').addEventListener('submit', handleBulkUpdate);
|
||||
document.getElementById('manual-scan-form').addEventListener('submit', handleManualScan);
|
||||
}
|
||||
|
||||
// API calls
|
||||
@@ -1436,6 +1437,169 @@ async function checkAuthStatus() {
|
||||
}
|
||||
}
|
||||
|
||||
// Manual Scan Functions
|
||||
async function handleManualScan(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const scanType = document.getElementById('scan-type').value;
|
||||
const scanMode = document.getElementById('scan-mode').value;
|
||||
const scanPath = document.getElementById('scan-path').value.trim();
|
||||
|
||||
// Validate inputs
|
||||
if (!scanType || !scanMode) {
|
||||
showToast('❌ Please select scan type and mode', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
// Build query parameters
|
||||
const params = new URLSearchParams({
|
||||
scan_type: scanType,
|
||||
scan_mode: scanMode
|
||||
});
|
||||
|
||||
if (scanPath) {
|
||||
params.append('path', scanPath);
|
||||
}
|
||||
|
||||
try {
|
||||
// Show scan status
|
||||
showScanStatus();
|
||||
|
||||
// Start the scan
|
||||
showToast('🚀 Starting manual scan...', 'info');
|
||||
const response = await fetch(`/manual/scan?${params}`, {
|
||||
method: 'POST',
|
||||
credentials: 'include'
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.status === 'started') {
|
||||
showToast('✅ Scan started successfully', 'success');
|
||||
// Start polling for status
|
||||
startScanPolling();
|
||||
} else {
|
||||
showToast(`ℹ️ ${result.message || 'Scan completed'}`, 'info');
|
||||
hideScanStatus();
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Manual scan failed:', error);
|
||||
showToast(`❌ Scan failed: ${error.message}`, 'error');
|
||||
hideScanStatus();
|
||||
}
|
||||
}
|
||||
|
||||
function showScanStatus() {
|
||||
const scanStatus = document.getElementById('scan-status');
|
||||
const progressBar = document.getElementById('scan-progress-bar');
|
||||
const operationText = document.getElementById('scan-current-operation');
|
||||
const progressText = document.getElementById('scan-progress-text');
|
||||
|
||||
// Reset and show
|
||||
progressBar.style.width = '0%';
|
||||
operationText.textContent = 'Initializing scan...';
|
||||
progressText.textContent = '0%';
|
||||
scanStatus.style.display = 'block';
|
||||
}
|
||||
|
||||
function hideScanStatus() {
|
||||
document.getElementById('scan-status').style.display = 'none';
|
||||
if (window.scanPollingInterval) {
|
||||
clearInterval(window.scanPollingInterval);
|
||||
window.scanPollingInterval = null;
|
||||
}
|
||||
}
|
||||
|
||||
function stopScanPolling() {
|
||||
hideScanStatus();
|
||||
}
|
||||
|
||||
function startScanPolling() {
|
||||
// Poll every 2 seconds for scan status
|
||||
window.scanPollingInterval = setInterval(async () => {
|
||||
try {
|
||||
const response = await fetch('/api/scan/status');
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to get scan status');
|
||||
}
|
||||
|
||||
const status = await response.json();
|
||||
updateScanProgress(status);
|
||||
|
||||
// Stop polling if scan is complete
|
||||
if (!status.scanning) {
|
||||
stopScanPolling();
|
||||
showToast('✅ Scan completed!', 'success');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Failed to poll scan status:', error);
|
||||
// Don't show error toast repeatedly, just stop polling
|
||||
stopScanPolling();
|
||||
}
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
function updateScanProgress(status) {
|
||||
const progressBar = document.getElementById('scan-progress-bar');
|
||||
const operationText = document.getElementById('scan-current-operation');
|
||||
const progressText = document.getElementById('scan-progress-text');
|
||||
|
||||
if (!status.scanning) {
|
||||
progressBar.style.width = '100%';
|
||||
operationText.textContent = 'Scan completed';
|
||||
progressText.textContent = '100%';
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculate overall progress
|
||||
let totalProgress = 0;
|
||||
let progressDetails = '';
|
||||
|
||||
if (status.scan_type === 'both' || status.scan_type === 'tv') {
|
||||
const tvProgress = status.tv_series_total > 0 ?
|
||||
((status.tv_series_processed + status.tv_series_skipped) / status.tv_series_total) * 50 : 0;
|
||||
totalProgress += tvProgress;
|
||||
|
||||
if (status.tv_series_total > 0) {
|
||||
progressDetails += `TV: ${status.tv_series_processed + status.tv_series_skipped}/${status.tv_series_total} `;
|
||||
}
|
||||
}
|
||||
|
||||
if (status.scan_type === 'both' || status.scan_type === 'movies') {
|
||||
const movieProgress = status.movies_total > 0 ?
|
||||
((status.movies_processed + status.movies_skipped) / status.movies_total) * 50 : 0;
|
||||
totalProgress += movieProgress;
|
||||
|
||||
if (status.movies_total > 0) {
|
||||
progressDetails += `Movies: ${status.movies_processed + status.movies_skipped}/${status.movies_total}`;
|
||||
}
|
||||
}
|
||||
|
||||
// For single type scans, use full 100%
|
||||
if (status.scan_type !== 'both') {
|
||||
totalProgress *= 2;
|
||||
}
|
||||
|
||||
// Update progress bar
|
||||
progressBar.style.width = `${Math.min(totalProgress, 100)}%`;
|
||||
progressText.textContent = `${Math.round(totalProgress)}%`;
|
||||
|
||||
// Update operation text
|
||||
if (status.current_operation) {
|
||||
operationText.textContent = status.current_operation;
|
||||
} else if (status.current_item) {
|
||||
operationText.textContent = `Processing: ${status.current_item}`;
|
||||
} else {
|
||||
operationText.textContent = progressDetails || 'Scanning...';
|
||||
}
|
||||
}
|
||||
|
||||
async function logout() {
|
||||
if (!confirm('Are you sure you want to logout?')) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user