v1.0.31: чтение всех файлов ДО отправки — разделение фаз

This commit is contained in:
2026-06-18 21:02:15 +04:00
parent d3516f1454
commit 6891e4a805
+37 -25
View File
@@ -64,7 +64,7 @@
<body> <body>
<div class="topbar"> <div class="topbar">
<img src="/nubes-logo.svg" alt="Nubes"> <img src="/nubes-logo.svg" alt="Nubes">
<span class="title">Сверка договоров <span style="font-weight:400;color:var(--muted);font-size:12px;">v1.0.30 — Lucee</span></span> <span class="title">Сверка договоров <span style="font-weight:400;color:var(--muted);font-size:12px;">v1.0.31 — Lucee</span></span>
</div> </div>
<div class="content"> <div class="content">
@@ -221,15 +221,40 @@ fileInput.addEventListener('change', function() {
renderTable(); renderTable();
}); });
// ── Загрузка (последовательно, каждый файл — JSON POST) // ── Загрузка (читаем все → шлём по одному) ────────────
uploadBtn.addEventListener('click', function() { uploadBtn.addEventListener('click', function() {
if (fileQueue.length === 0) return; if (fileQueue.length === 0) return;
uploadBtn.disabled = true; uploadBtn.disabled = true;
uploadStartTime = Date.now(); uploadStartTime = Date.now();
uploadTimer.style.display = 'block'; uploadTimer.style.display = 'block';
function uploadNext(i) { var pending = fileQueue.filter(function(f) { return !f.doc_id; });
if (i >= fileQueue.length) { var payloads = [];
var readIdx = 0;
function readAll() {
if (readIdx >= pending.length) { sendSeq(0); return; }
var f = pending[readIdx];
f.status = 'читаю...';
renderTable();
var reader = new FileReader();
reader.onload = function(e) {
payloads.push({file: f, b64: e.target.result.split(',')[1]});
readIdx++;
uploadTimer.textContent = 'Чтение ' + readIdx + '/' + pending.length;
readAll();
};
reader.onerror = function() {
f.status = 'error: чтение';
renderTable();
readIdx++;
readAll();
};
reader.readAsDataURL(f.file);
}
function sendSeq(i) {
if (i >= payloads.length) {
uploadTimer.style.display = 'none'; uploadTimer.style.display = 'none';
uploadBtn.disabled = false; uploadBtn.disabled = false;
var hasErrors = fileQueue.some(function(f) { return f.status && f.status.indexOf('error') === 0; }); var hasErrors = fileQueue.some(function(f) { return f.status && f.status.indexOf('error') === 0; });
@@ -239,17 +264,10 @@ uploadBtn.addEventListener('click', function() {
} }
return; return;
} }
var f = fileQueue[i]; var p = payloads[i];
if (f.doc_id) { uploadNext(i + 1); return; } var f = p.file;
uploadTimer.textContent = 'Отправка ' + (i+1) + '/' + payloads.length;
f.status = 'читаю...'; var payload = {filename: f.name, data: p.b64};
renderTable();
uploadTimer.textContent = 'Загрузка ' + (i+1) + '/' + fileQueue.length + '...';
var reader = new FileReader();
reader.onload = function(e) {
var b64 = e.target.result.split(',')[1];
var payload = {filename: f.name, data: b64};
if (contractId) payload.contract_id = contractId; if (contractId) payload.contract_id = contractId;
fetch('/upload.cfm', { fetch('/upload.cfm', {
@@ -269,22 +287,16 @@ uploadBtn.addEventListener('click', function() {
log('❌ ' + f.name + ': ' + (r.ERROR || '')); log('❌ ' + f.name + ': ' + (r.ERROR || ''));
} }
renderTable(); renderTable();
uploadNext(i + 1); sendSeq(i + 1);
}).catch(function(e) { }).catch(function(e) {
f.status = 'error: ' + e.message; f.status = 'error: ' + e.message;
log('❌ ' + f.name + ': ' + e.message); log('❌ ' + f.name + ': ' + e.message);
renderTable(); renderTable();
uploadNext(i + 1); sendSeq(i + 1);
}); });
};
reader.onerror = function() {
f.status = 'error: чтение';
renderTable();
uploadNext(i + 1);
};
reader.readAsDataURL(f.file);
} }
uploadNext(0);
readAll();
}); });
// ── Инфо ────────────────────────────────────────────────── // ── Инфо ──────────────────────────────────────────────────