v1.0.29: возврат последовательной загрузки (один запрос > nginx лимит)

This commit is contained in:
2026-06-18 20:49:35 +04:00
parent 17517e0e60
commit d42b2966af
+48 -76
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.28 — Lucee</span></span> <span class="title">Сверка договоров <span style="font-weight:400;color:var(--muted);font-size:12px;">v1.0.29 — Lucee</span></span>
</div> </div>
<div class="content"> <div class="content">
@@ -221,98 +221,70 @@ fileInput.addEventListener('change', function() {
renderTable(); renderTable();
}); });
// ── Загрузка (FileReader → base64 → JSON POST все сразу) ─ // ── Загрузка (последовательно, каждый файл — 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';
// Читаем все файлы в base64 function uploadNext(i) {
var pending = fileQueue.filter(function(f) { return !f.doc_id; }); if (i >= fileQueue.length) {
var done = 0;
var payloads = [];
function readNext(i) {
if (i >= pending.length) { sendAll(); return; }
var f = pending[i];
f.status = 'читаю...';
renderTable();
var reader = new FileReader();
reader.onload = function(e) {
payloads.push({filename: f.name, data: e.target.result.split(',')[1]});
done++;
uploadTimer.textContent = 'Чтение ' + done + '/' + pending.length + '...';
readNext(i + 1);
};
reader.onerror = function() {
f.status = 'error: чтение';
renderTable();
readNext(i + 1);
};
reader.readAsDataURL(f.file);
}
function sendAll() {
if (payloads.length === 0) {
uploadTimer.style.display = 'none'; uploadTimer.style.display = 'none';
uploadBtn.disabled = false; uploadBtn.disabled = false;
return;
}
uploadTimer.textContent = 'Отправка ' + payloads.length + ' файлов...';
var body = {files: payloads};
if (contractId) body.contract_id = contractId;
fetch('/upload.cfm', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(body)
}).then(function(r) { return r.json(); })
.then(function(data) {
uploadTimer.style.display = 'none';
uploadBtn.disabled = false;
if (data.OK && data.RESULTS) {
for (var i = 0; i < data.RESULTS.length; i++) {
var r = data.RESULTS[i];
// Найти файл в очереди по имени
for (var j = 0; j < fileQueue.length; j++) {
if (fileQueue[j].name === r.filename) {
if (r.OK) {
fileQueue[j].status = 'uploaded';
fileQueue[j].doc_id = r.DOC_ID;
contractId = r.CONTRACT_ID || contractId;
log('✅ ' + r.filename + ' (' + formatSize(fileQueue[j].size) + ')');
} else {
fileQueue[j].status = 'error: ' + (r.ERROR || '');
log('❌ ' + r.filename + ': ' + (r.ERROR || ''));
}
}
}
}
} else {
log('❌ ' + (data.ERROR || 'неизв. ошибка'));
for (var i = 0; i < pending.length; i++) {
pending[i].status = 'error';
}
}
renderTable();
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; });
if (contractId && !hasErrors) { if (contractId && !hasErrors) {
document.getElementById('actionsCard').style.display = 'block'; document.getElementById('actionsCard').style.display = 'block';
document.getElementById('chatCard').style.display = 'block'; document.getElementById('chatCard').style.display = 'block';
} }
}).catch(function(e) { return;
uploadTimer.style.display = 'none'; }
uploadBtn.disabled = false; var f = fileQueue[i];
log('❌ Сеть: ' + e.message); if (f.doc_id) { uploadNext(i + 1); return; }
for (var i = 0; i < pending.length; i++) {
pending[i].status = 'error: ' + e.message; 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(); 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);
} }
uploadNext(0);
readNext(0);
}); });
// ── Инфо ────────────────────────────────────────────────── // ── Инфо ──────────────────────────────────────────────────