Update script.js
This commit is contained in:
parent
8712209bb9
commit
3b936d6fdb
1 changed files with 68 additions and 41 deletions
|
|
@ -19733,17 +19733,11 @@ async function handleMediaScanButtonClick() {
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
// Update UI to show scan in progress
|
// Get delay from API response (graceful fallback to 60 if not provided)
|
||||||
phaseLabel.textContent = 'Scan in progress...';
|
const delaySeconds = (result.scan_info && result.scan_info.delay_seconds) || 60;
|
||||||
progressBar.style.width = '100%';
|
let remainingSeconds = delaySeconds;
|
||||||
|
let countdownInterval = null;
|
||||||
if (result.scan_info && result.scan_info.delay_seconds) {
|
let pollInterval = null;
|
||||||
progressLabel.textContent = `Scan scheduled (${result.scan_info.delay_seconds}s delay)`;
|
|
||||||
showToast(`📡 Media scan scheduled (${result.scan_info.delay_seconds}s delay)`, 'success', 5000);
|
|
||||||
} else {
|
|
||||||
progressLabel.textContent = 'Scan initiated successfully';
|
|
||||||
showToast('📡 Media scan initiated successfully', 'success', 3000);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show auto database update message
|
// Show auto database update message
|
||||||
if (result.auto_database_update) {
|
if (result.auto_database_update) {
|
||||||
|
|
@ -19757,50 +19751,83 @@ async function handleMediaScanButtonClick() {
|
||||||
lastTimeEl.textContent = now.toLocaleTimeString();
|
lastTimeEl.textContent = now.toLocaleTimeString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Poll scan status for ~30 seconds
|
// Start countdown timer (visual feedback during delay)
|
||||||
let pollCount = 0;
|
phaseLabel.textContent = 'Scan scheduled...';
|
||||||
const pollInterval = setInterval(async () => {
|
progressBar.style.width = '0%';
|
||||||
pollCount++;
|
|
||||||
|
|
||||||
if (pollCount > 15) { // Stop after 30 seconds (15 * 2s)
|
countdownInterval = setInterval(() => {
|
||||||
clearInterval(pollInterval);
|
remainingSeconds--;
|
||||||
// Reset UI
|
|
||||||
button.disabled = false;
|
// Update progress bar (0% -> 100% over delay period)
|
||||||
phaseLabel.textContent = 'Scan completed';
|
const progress = ((delaySeconds - remainingSeconds) / delaySeconds) * 100;
|
||||||
progressBar.style.width = '0%';
|
progressBar.style.width = `${progress}%`;
|
||||||
progressLabel.textContent = 'Ready for next scan';
|
|
||||||
statusValue.textContent = 'Idle';
|
// Update progress label with countdown
|
||||||
statusValue.style.color = '#b3b3b3';
|
if (remainingSeconds > 0) {
|
||||||
return;
|
progressLabel.textContent = `Starting scan in ${remainingSeconds}s...`;
|
||||||
|
} else {
|
||||||
|
progressLabel.textContent = 'Scan starting now...';
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
// When countdown reaches 0, start polling
|
||||||
const statusResponse = await fetch('/api/scan/status');
|
if (remainingSeconds <= 0) {
|
||||||
const statusData = await statusResponse.json();
|
clearInterval(countdownInterval);
|
||||||
|
|
||||||
if (statusData.success && statusData.status) {
|
// Transition to scanning phase
|
||||||
const status = statusData.status;
|
phaseLabel.textContent = 'Scan in progress...';
|
||||||
|
progressBar.style.width = '100%';
|
||||||
|
progressLabel.textContent = 'Media server is scanning library...';
|
||||||
|
showToast('📡 Media scan started', 'success', 3000);
|
||||||
|
|
||||||
// Update status display
|
// Start polling for scan completion (5 minutes = 150 polls × 2s)
|
||||||
if (status.is_scanning) {
|
let pollCount = 0;
|
||||||
phaseLabel.textContent = 'Plex is scanning library...';
|
const maxPolls = 150; // 5 minutes
|
||||||
progressLabel.textContent = status.progress_message || 'Scan in progress';
|
|
||||||
} else {
|
pollInterval = setInterval(async () => {
|
||||||
// Scan complete
|
pollCount++;
|
||||||
|
|
||||||
|
if (pollCount > maxPolls) {
|
||||||
|
// Polling timeout after 5 minutes
|
||||||
clearInterval(pollInterval);
|
clearInterval(pollInterval);
|
||||||
button.disabled = false;
|
button.disabled = false;
|
||||||
phaseLabel.textContent = 'Scan completed successfully';
|
phaseLabel.textContent = 'Scan completed';
|
||||||
progressBar.style.width = '0%';
|
progressBar.style.width = '0%';
|
||||||
progressLabel.textContent = 'Ready for next scan';
|
progressLabel.textContent = 'Ready for next scan';
|
||||||
statusValue.textContent = 'Idle';
|
statusValue.textContent = 'Idle';
|
||||||
statusValue.style.color = '#b3b3b3';
|
statusValue.style.color = '#b3b3b3';
|
||||||
showToast('✅ Media scan completed', 'success', 3000);
|
showToast('✅ Media scan completed', 'success', 3000);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch (pollError) {
|
try {
|
||||||
console.debug('Scan status poll error:', pollError);
|
const statusResponse = await fetch('/api/scan/status');
|
||||||
|
const statusData = await statusResponse.json();
|
||||||
|
|
||||||
|
if (statusData.success && statusData.status) {
|
||||||
|
const status = statusData.status;
|
||||||
|
|
||||||
|
// Update status display
|
||||||
|
if (status.is_scanning) {
|
||||||
|
phaseLabel.textContent = 'Media server scanning...';
|
||||||
|
progressLabel.textContent = status.progress_message || 'Scan in progress';
|
||||||
|
} else if (status.status === 'idle') {
|
||||||
|
// Scan completed
|
||||||
|
clearInterval(pollInterval);
|
||||||
|
button.disabled = false;
|
||||||
|
phaseLabel.textContent = 'Scan completed successfully';
|
||||||
|
progressBar.style.width = '0%';
|
||||||
|
progressLabel.textContent = 'Ready for next scan';
|
||||||
|
statusValue.textContent = 'Idle';
|
||||||
|
statusValue.style.color = '#b3b3b3';
|
||||||
|
showToast('✅ Media scan completed', 'success', 3000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (pollError) {
|
||||||
|
console.debug('Scan status poll error:', pollError);
|
||||||
|
}
|
||||||
|
}, 2000); // Poll every 2 seconds
|
||||||
}
|
}
|
||||||
}, 2000); // Poll every 2 seconds
|
}, 1000); // Update countdown every second
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Error occurred
|
// Error occurred
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue