v0.0.7: SSE per-file progress — таблица обновляется по каждому файлу
Deploy drhider / validate (push) Waiting to run

This commit is contained in:
2026-07-13 10:55:43 +04:00
parent 46d8ced0dd
commit e3405556b5
3 changed files with 83 additions and 16 deletions
+26 -9
View File
@@ -203,7 +203,7 @@ async function uploadFiles() {
}
}
// Фаза 2: обработка
// Фаза 2: обработка (SSE — прогресс по каждому файлу)
for (let i = 0; i < total; i++) ss(i, '<span style="color:#2563eb">⏳</span>');
st.className = 'status progress';
st.textContent = 'Обработка...';
@@ -214,14 +214,31 @@ async function uploadFiles() {
}, 1000);
try {
const resp = await fetch('/api/process/' + currentSid, { method: 'POST' });
const data = await resp.json();
clearInterval(ptimer);
if (!data.ok) throw new Error(data.error);
for (let i = 0; i < total; i++) ss(i, '<span style="color:#22c55e">✓</span>');
st.className = 'status done';
st.textContent = '✅ Обработано ' + data.files + ' файлов за ' + ((performance.now() - t0) / 1000).toFixed(1) + 'с';
db.classList.add('show');
await new Promise((resolve, reject) => {
const es = new EventSource('/api/process_stream/' + currentSid);
es.addEventListener('start', function(e) {
const d = JSON.parse(e.data);
ss(d.idx, '<span style="color:#2563eb">⏳ обработка</span>');
});
es.addEventListener('done', function(e) {
const d = JSON.parse(e.data);
ss(d.idx, '<span style="color:#22c55e">✓</span>');
});
es.addEventListener('complete', function(e) {
es.close();
clearInterval(ptimer);
const d = JSON.parse(e.data);
st.className = 'status done';
st.textContent = '✅ Обработано ' + d.total + ' файлов за ' + ((performance.now() - t0) / 1000).toFixed(1) + 'с';
db.classList.add('show');
resolve();
});
es.onerror = function() {
es.close();
clearInterval(ptimer);
reject(new Error('SSE connection failed'));
};
});
} catch (err) {
clearInterval(ptimer);
st.className = 'status error';