Fix upload 'processing' status
This commit is contained in:
@@ -5,9 +5,14 @@
|
||||
<div class="col-12">
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h2><i class="fas fa-tachometer-alt me-2"></i>Your Dashboard</h2>
|
||||
<a href="/upload" class="btn btn-primary">
|
||||
<i class="fas fa-plus me-2"></i>Upload New Notes
|
||||
</a>
|
||||
<div>
|
||||
<button class="btn btn-outline-secondary me-2" onclick="refreshStatus()" id="refreshBtn">
|
||||
<i class="fas fa-sync-alt me-1"></i>Refresh Status
|
||||
</button>
|
||||
<a href="/upload" class="btn btn-primary">
|
||||
<i class="fas fa-plus me-2"></i>Upload New Notes
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% if (files.length === 0) { %>
|
||||
@@ -497,6 +502,49 @@ async function viewProcessingDetails(fileId) {
|
||||
// Progress monitoring for processing files
|
||||
let progressMonitoring = {};
|
||||
|
||||
// Manual refresh function
|
||||
async function refreshStatus() {
|
||||
const refreshBtn = document.getElementById('refreshBtn');
|
||||
const originalHtml = refreshBtn.innerHTML;
|
||||
|
||||
refreshBtn.innerHTML = '<i class="fas fa-spinner fa-spin me-1"></i>Refreshing...';
|
||||
refreshBtn.disabled = true;
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/files/status/all');
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
console.log('Status refresh successful:', result.summary);
|
||||
|
||||
// Check if status has changed - if so, reload page to show updates
|
||||
const hasProcessingFiles = result.summary.processing > 0;
|
||||
const currentProcessingBadges = document.querySelectorAll('.badge').length;
|
||||
|
||||
if (!hasProcessingFiles || result.summary.processed > 0) {
|
||||
console.log('Status changed, reloading page...');
|
||||
location.reload();
|
||||
} else {
|
||||
// Show success feedback
|
||||
refreshBtn.innerHTML = '<i class="fas fa-check me-1"></i>Updated';
|
||||
setTimeout(() => {
|
||||
refreshBtn.innerHTML = originalHtml;
|
||||
refreshBtn.disabled = false;
|
||||
}, 1500);
|
||||
}
|
||||
} else {
|
||||
throw new Error(result.error || 'Failed to refresh status');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error refreshing status:', error);
|
||||
refreshBtn.innerHTML = '<i class="fas fa-exclamation-triangle me-1"></i>Error';
|
||||
setTimeout(() => {
|
||||
refreshBtn.innerHTML = originalHtml;
|
||||
refreshBtn.disabled = false;
|
||||
}, 2000);
|
||||
}
|
||||
}
|
||||
|
||||
function startProgressMonitoring() {
|
||||
// Find all processing files and start monitoring them
|
||||
const processingCards = document.querySelectorAll('.card');
|
||||
@@ -534,19 +582,19 @@ function startFileProgressMonitoring(fileId) {
|
||||
|
||||
// Stop monitoring if processing is complete
|
||||
if (result.progress.status !== 'processing') {
|
||||
console.log(`File ${fileId} finished processing with status: ${result.progress.status}`);
|
||||
clearInterval(progressMonitoring[fileId]);
|
||||
delete progressMonitoring[fileId];
|
||||
|
||||
// Refresh page to show final status
|
||||
setTimeout(() => {
|
||||
location.reload();
|
||||
}, 2000);
|
||||
// Reload page immediately to show final status
|
||||
console.log('Reloading page to show updated status...');
|
||||
location.reload();
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error checking progress:', error);
|
||||
}
|
||||
}, 2000); // Check every 2 seconds
|
||||
}, 1000); // Check every 1 second for faster updates
|
||||
}
|
||||
|
||||
function updateProgressDisplay(fileId, progress) {
|
||||
@@ -631,7 +679,7 @@ function stopAllProgressMonitoring() {
|
||||
// Clean up when page unloads
|
||||
window.addEventListener('beforeunload', stopAllProgressMonitoring);
|
||||
|
||||
// Auto-refresh processing status every 10 seconds for files that are still processing
|
||||
// Auto-refresh processing status for files that are still processing
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Start progress monitoring for processing files
|
||||
startProgressMonitoring();
|
||||
@@ -648,8 +696,31 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
if (hasProcessingFiles) {
|
||||
console.log('Found processing files, setting up auto-refresh...');
|
||||
setInterval(() => {
|
||||
// Check again if there are still processing files
|
||||
|
||||
// More frequent checking - every 3 seconds
|
||||
const statusCheckInterval = setInterval(async () => {
|
||||
console.log('Checking file statuses...');
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/files/status/all');
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
console.log('Status check result:', result.summary);
|
||||
|
||||
// If no more processing files, reload page to show final status
|
||||
if (result.summary.processing === 0) {
|
||||
console.log('No more processing files, reloading page...');
|
||||
clearInterval(statusCheckInterval);
|
||||
location.reload();
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error in status check:', error);
|
||||
}
|
||||
|
||||
// Also check DOM for processing badges
|
||||
const currentBadges = document.querySelectorAll('.badge');
|
||||
let stillProcessing = false;
|
||||
|
||||
@@ -659,11 +730,22 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
}
|
||||
});
|
||||
|
||||
if (stillProcessing) {
|
||||
console.log('Still have processing files, refreshing page...');
|
||||
if (!stillProcessing) {
|
||||
console.log('No processing badges found, reloading page...');
|
||||
clearInterval(statusCheckInterval);
|
||||
location.reload();
|
||||
}
|
||||
}, 10000); // Check every 10 seconds
|
||||
}, 3000); // Check every 3 seconds
|
||||
|
||||
// Also add a manual refresh reminder
|
||||
setTimeout(() => {
|
||||
const processingBadges = Array.from(document.querySelectorAll('.badge')).filter(badge =>
|
||||
badge.textContent && badge.textContent.includes('Processing')
|
||||
);
|
||||
if (processingBadges.length > 0) {
|
||||
console.log('Files still processing after 10 seconds, you can click refresh manually');
|
||||
}
|
||||
}, 10000);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user