v1.0.31: чтение всех файлов ДО отправки — разделение фаз
This commit is contained in:
@@ -64,7 +64,7 @@
|
||||
<body>
|
||||
<div class="topbar">
|
||||
<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 class="content">
|
||||
@@ -221,15 +221,40 @@ fileInput.addEventListener('change', function() {
|
||||
renderTable();
|
||||
});
|
||||
|
||||
// ── Загрузка (последовательно, каждый файл — JSON POST) ─
|
||||
// ── Загрузка (читаем все → шлём по одному) ─────────────
|
||||
uploadBtn.addEventListener('click', function() {
|
||||
if (fileQueue.length === 0) return;
|
||||
uploadBtn.disabled = true;
|
||||
uploadStartTime = Date.now();
|
||||
uploadTimer.style.display = 'block';
|
||||
|
||||
function uploadNext(i) {
|
||||
if (i >= fileQueue.length) {
|
||||
var pending = fileQueue.filter(function(f) { return !f.doc_id; });
|
||||
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';
|
||||
uploadBtn.disabled = false;
|
||||
var hasErrors = fileQueue.some(function(f) { return f.status && f.status.indexOf('error') === 0; });
|
||||
@@ -239,52 +264,39 @@ uploadBtn.addEventListener('click', function() {
|
||||
}
|
||||
return;
|
||||
}
|
||||
var f = fileQueue[i];
|
||||
if (f.doc_id) { uploadNext(i + 1); return; }
|
||||
var p = payloads[i];
|
||||
var f = p.file;
|
||||
uploadTimer.textContent = 'Отправка ' + (i+1) + '/' + payloads.length;
|
||||
var payload = {filename: f.name, data: p.b64};
|
||||
if (contractId) payload.contract_id = contractId;
|
||||
|
||||
f.status = 'читаю...';
|
||||
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;
|
||||
|
||||
fetch('/upload.cfm', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify(payload)
|
||||
}).then(function(r) { return r.json(); })
|
||||
.then(function(r) {
|
||||
if (r.OK) {
|
||||
contractId = r.CONTRACT_ID;
|
||||
f.doc_id = r.DOC_ID;
|
||||
f.status = 'uploaded';
|
||||
var elapsed = ((Date.now() - uploadStartTime) / 1000).toFixed(1);
|
||||
log('✅ ' + f.name + ' (' + formatSize(f.size) + ') — ' + elapsed + 'с');
|
||||
} else {
|
||||
f.status = 'error: ' + (r.ERROR || 'неизв.');
|
||||
log('❌ ' + f.name + ': ' + (r.ERROR || ''));
|
||||
}
|
||||
renderTable();
|
||||
uploadNext(i + 1);
|
||||
}).catch(function(e) {
|
||||
f.status = 'error: ' + e.message;
|
||||
log('❌ ' + f.name + ': ' + e.message);
|
||||
renderTable();
|
||||
uploadNext(i + 1);
|
||||
});
|
||||
};
|
||||
reader.onerror = function() {
|
||||
f.status = 'error: чтение';
|
||||
renderTable();
|
||||
uploadNext(i + 1);
|
||||
};
|
||||
reader.readAsDataURL(f.file);
|
||||
fetch('/upload.cfm', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify(payload)
|
||||
}).then(function(r) { return r.json(); })
|
||||
.then(function(r) {
|
||||
if (r.OK) {
|
||||
contractId = r.CONTRACT_ID;
|
||||
f.doc_id = r.DOC_ID;
|
||||
f.status = 'uploaded';
|
||||
var elapsed = ((Date.now() - uploadStartTime) / 1000).toFixed(1);
|
||||
log('✅ ' + f.name + ' (' + formatSize(f.size) + ') — ' + elapsed + 'с');
|
||||
} else {
|
||||
f.status = 'error: ' + (r.ERROR || 'неизв.');
|
||||
log('❌ ' + f.name + ': ' + (r.ERROR || ''));
|
||||
}
|
||||
renderTable();
|
||||
sendSeq(i + 1);
|
||||
}).catch(function(e) {
|
||||
f.status = 'error: ' + e.message;
|
||||
log('❌ ' + f.name + ': ' + e.message);
|
||||
renderTable();
|
||||
sendSeq(i + 1);
|
||||
});
|
||||
}
|
||||
uploadNext(0);
|
||||
|
||||
readAll();
|
||||
});
|
||||
|
||||
// ── Инфо ──────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user