fix streaming of the logs
This commit is contained in:
@@ -131,6 +131,17 @@
|
||||
.loading-text {
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.progress-text {
|
||||
color: #667eea;
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
margin-top: 15px;
|
||||
padding: 10px;
|
||||
background: #f0f3ff;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.results {
|
||||
@@ -282,8 +293,8 @@
|
||||
|
||||
<div class="loading" id="loading">
|
||||
<div class="spinner"></div>
|
||||
<div class="loading-text">Processing... This may take a few minutes.</div>
|
||||
<div class="loading-text" style="margin-top: 10px; font-size: 12px;">Please be patient, downloading and converting can take time.</div>
|
||||
<div class="loading-text">Processing your request...</div>
|
||||
<div class="progress-text" id="progressText">Initializing...</div>
|
||||
</div>
|
||||
|
||||
<div class="error" id="error"></div>
|
||||
@@ -323,6 +334,76 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let pollInterval = null;
|
||||
|
||||
async function pollJobStatus(jobId) {
|
||||
try {
|
||||
const response = await fetch(`/status/${jobId}`);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to fetch job status');
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
// Update progress text
|
||||
document.getElementById('progressText').textContent = data.progress || 'Processing...';
|
||||
|
||||
if (data.status === 'completed') {
|
||||
// Stop polling
|
||||
clearInterval(pollInterval);
|
||||
|
||||
// Display results
|
||||
const result = data.result;
|
||||
document.getElementById('resultAlbum').textContent = result.album;
|
||||
document.getElementById('resultArtist').textContent = result.artist;
|
||||
document.getElementById('resultTotal').textContent = result.total_tracks;
|
||||
document.getElementById('resultCreated').textContent = result.created_count;
|
||||
document.getElementById('resultSkipped').textContent = result.skipped_count;
|
||||
document.getElementById('resultDir').textContent = result.output_dir;
|
||||
|
||||
// Display tracks
|
||||
const tracksList = document.getElementById('tracksList');
|
||||
tracksList.innerHTML = '';
|
||||
result.tracks.forEach(track => {
|
||||
const trackItem = document.createElement('div');
|
||||
trackItem.className = 'track-item';
|
||||
trackItem.innerHTML = `
|
||||
<span class="track-filename">${track.filename}</span>
|
||||
<span class="track-status ${track.status}">${track.status}</span>
|
||||
`;
|
||||
tracksList.appendChild(trackItem);
|
||||
});
|
||||
|
||||
// Show results, hide loading
|
||||
document.getElementById('loading').classList.remove('active');
|
||||
document.getElementById('results').classList.add('active');
|
||||
document.getElementById('splitForm').querySelector('button').disabled = false;
|
||||
|
||||
} else if (data.status === 'failed') {
|
||||
// Stop polling
|
||||
clearInterval(pollInterval);
|
||||
|
||||
// Show error
|
||||
document.getElementById('loading').classList.remove('active');
|
||||
const errorDiv = document.getElementById('error');
|
||||
errorDiv.textContent = data.error || 'Processing failed';
|
||||
errorDiv.classList.add('active');
|
||||
document.getElementById('splitForm').querySelector('button').disabled = false;
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error polling status:', error);
|
||||
clearInterval(pollInterval);
|
||||
|
||||
document.getElementById('loading').classList.remove('active');
|
||||
const errorDiv = document.getElementById('error');
|
||||
errorDiv.textContent = 'Lost connection to server. Check server logs.';
|
||||
errorDiv.classList.add('active');
|
||||
document.getElementById('splitForm').querySelector('button').disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
document.getElementById('splitForm').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
@@ -333,72 +414,42 @@
|
||||
document.getElementById('loading').classList.add('active');
|
||||
document.getElementById('results').classList.remove('active');
|
||||
document.getElementById('error').classList.remove('active');
|
||||
document.getElementById('progressText').textContent = 'Submitting job...';
|
||||
form.querySelector('button').disabled = true;
|
||||
|
||||
try {
|
||||
// Increase timeout to 10 minutes (600000ms)
|
||||
const controller = new AbortController();
|
||||
const timeoutId = setTimeout(() => controller.abort(), 600000);
|
||||
|
||||
// Submit job
|
||||
const response = await fetch('/split', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
signal: controller.signal
|
||||
body: formData
|
||||
});
|
||||
|
||||
clearTimeout(timeoutId);
|
||||
|
||||
// Check if response is JSON
|
||||
const contentType = response.headers.get('content-type');
|
||||
if (!contentType || !contentType.includes('application/json')) {
|
||||
throw new Error('Server returned non-JSON response. Check server logs.');
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data.error || 'Unknown error occurred');
|
||||
throw new Error(data.error || 'Failed to submit job');
|
||||
}
|
||||
|
||||
if (data.success) {
|
||||
// Display results
|
||||
document.getElementById('resultAlbum').textContent = data.album;
|
||||
document.getElementById('resultArtist').textContent = data.artist;
|
||||
document.getElementById('resultTotal').textContent = data.total_tracks;
|
||||
document.getElementById('resultCreated').textContent = data.created_count;
|
||||
document.getElementById('resultSkipped').textContent = data.skipped_count;
|
||||
document.getElementById('resultDir').textContent = data.output_dir;
|
||||
if (data.success && data.job_id) {
|
||||
// Start polling for status
|
||||
document.getElementById('progressText').textContent = 'Job submitted. Waiting for processing...';
|
||||
|
||||
// Display tracks
|
||||
const tracksList = document.getElementById('tracksList');
|
||||
tracksList.innerHTML = '';
|
||||
data.tracks.forEach(track => {
|
||||
const trackItem = document.createElement('div');
|
||||
trackItem.className = 'track-item';
|
||||
trackItem.innerHTML = `
|
||||
<span class="track-filename">${track.filename}</span>
|
||||
<span class="track-status ${track.status}">${track.status}</span>
|
||||
`;
|
||||
tracksList.appendChild(trackItem);
|
||||
});
|
||||
pollInterval = setInterval(() => {
|
||||
pollJobStatus(data.job_id);
|
||||
}, 2000); // Poll every 2 seconds
|
||||
|
||||
document.getElementById('results').classList.add('active');
|
||||
// Also poll immediately
|
||||
pollJobStatus(data.job_id);
|
||||
} else {
|
||||
throw new Error(data.error || 'Processing failed');
|
||||
throw new Error('Invalid response from server');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error:', error);
|
||||
const errorDiv = document.getElementById('error');
|
||||
|
||||
if (error.name === 'AbortError') {
|
||||
errorDiv.textContent = 'Request timed out. The download is taking too long. Please try with a shorter video or check your internet connection.';
|
||||
} else {
|
||||
errorDiv.textContent = error.message || 'An error occurred. Check the console for details.';
|
||||
}
|
||||
|
||||
errorDiv.classList.add('active');
|
||||
} finally {
|
||||
document.getElementById('loading').classList.remove('active');
|
||||
const errorDiv = document.getElementById('error');
|
||||
errorDiv.textContent = error.message || 'An error occurred';
|
||||
errorDiv.classList.add('active');
|
||||
form.querySelector('button').disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user