diff --git a/index.cfm b/index.cfm
index de9d17d..7abfb2e 100644
--- a/index.cfm
+++ b/index.cfm
@@ -64,7 +64,7 @@

-
Сверка договоров v1.0.28 — Lucee
+
Сверка договоров v1.0.29 — Lucee
@@ -221,98 +221,70 @@ fileInput.addEventListener('change', function() {
renderTable();
});
-// ── Загрузка (FileReader → base64 → JSON POST все сразу) ─
+// ── Загрузка (последовательно, каждый файл — JSON POST) ─
uploadBtn.addEventListener('click', function() {
if (fileQueue.length === 0) return;
uploadBtn.disabled = true;
uploadStartTime = Date.now();
uploadTimer.style.display = 'block';
- // Читаем все файлы в base64
- var pending = fileQueue.filter(function(f) { return !f.doc_id; });
- var done = 0;
- var payloads = [];
+ function uploadNext(i) {
+ if (i >= fileQueue.length) {
+ uploadTimer.style.display = 'none';
+ 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 = 'читаю...';
renderTable();
+ uploadTimer.textContent = 'Загрузка ' + (i+1) + '/' + fileQueue.length + '...';
+
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);
+ 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();
- readNext(i + 1);
+ uploadNext(i + 1);
};
reader.readAsDataURL(f.file);
}
-
- 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);
+ uploadNext(0);
});
// ── Инфо ──────────────────────────────────────────────────