v1.0.29: возврат последовательной загрузки (один запрос > nginx лимит)
This commit is contained in:
@@ -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;
|
uploadTimer.style.display = 'none';
|
||||||
var payloads = [];
|
uploadBtn.disabled = false;
|
||||||
|
var hasErrors = fileQueue.some(function(f) { return f.status && f.status.indexOf('error') === 0; });
|
||||||
|
if (contractId && !hasErrors) {
|
||||||
|
document.getElementById('actionsCard').style.display = 'block';
|
||||||
|
document.getElementById('chatCard').style.display = 'block';
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var f = fileQueue[i];
|
||||||
|
if (f.doc_id) { uploadNext(i + 1); return; }
|
||||||
|
|
||||||
function readNext(i) {
|
|
||||||
if (i >= pending.length) { sendAll(); return; }
|
|
||||||
var f = pending[i];
|
|
||||||
f.status = 'читаю...';
|
f.status = 'читаю...';
|
||||||
renderTable();
|
renderTable();
|
||||||
|
uploadTimer.textContent = 'Загрузка ' + (i+1) + '/' + fileQueue.length + '...';
|
||||||
|
|
||||||
var reader = new FileReader();
|
var reader = new FileReader();
|
||||||
reader.onload = function(e) {
|
reader.onload = function(e) {
|
||||||
payloads.push({filename: f.name, data: e.target.result.split(',')[1]});
|
var b64 = e.target.result.split(',')[1];
|
||||||
done++;
|
var payload = {filename: f.name, data: b64};
|
||||||
uploadTimer.textContent = 'Чтение ' + done + '/' + pending.length + '...';
|
if (contractId) payload.contract_id = contractId;
|
||||||
readNext(i + 1);
|
|
||||||
|
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() {
|
reader.onerror = function() {
|
||||||
f.status = 'error: чтение';
|
f.status = 'error: чтение';
|
||||||
renderTable();
|
renderTable();
|
||||||
readNext(i + 1);
|
uploadNext(i + 1);
|
||||||
};
|
};
|
||||||
reader.readAsDataURL(f.file);
|
reader.readAsDataURL(f.file);
|
||||||
}
|
}
|
||||||
|
uploadNext(0);
|
||||||
function sendAll() {
|
|
||||||
if (payloads.length === 0) {
|
|
||||||
uploadTimer.style.display = 'none';
|
|
||||||
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; });
|
|
||||||
if (contractId && !hasErrors) {
|
|
||||||
document.getElementById('actionsCard').style.display = 'block';
|
|
||||||
document.getElementById('chatCard').style.display = 'block';
|
|
||||||
}
|
|
||||||
}).catch(function(e) {
|
|
||||||
uploadTimer.style.display = 'none';
|
|
||||||
uploadBtn.disabled = false;
|
|
||||||
log('❌ Сеть: ' + e.message);
|
|
||||||
for (var i = 0; i < pending.length; i++) {
|
|
||||||
pending[i].status = 'error: ' + e.message;
|
|
||||||
}
|
|
||||||
renderTable();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
readNext(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── Инфо ──────────────────────────────────────────────────
|
// ── Инфо ──────────────────────────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user