v1.0.25: загрузка JSON/base64 — без бинарного multipart

This commit is contained in:
2026-06-18 19:49:57 +04:00
parent 51b9566046
commit bca1bba6d0
2 changed files with 110 additions and 100 deletions
+37 -41
View File
@@ -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.24 — Lucee</span></span>
<span class="title">Сверка договоров <span style="font-weight:400;color:var(--muted);font-size:12px;">v1.0.25 — Lucee</span></span>
</div>
<div class="content">
@@ -221,7 +221,7 @@ fileInput.addEventListener('change', function() {
renderTable();
});
// ── Загрузка (XHR с прогрессом) ──────────────────────────
// ── Загрузка (FileReader → base64 → JSON POST) ─────────
uploadBtn.addEventListener('click', function() {
if (fileQueue.length === 0) return;
uploadBtn.disabled = true;
@@ -241,53 +241,49 @@ uploadBtn.addEventListener('click', function() {
var f = fileQueue[i];
if (f.status === 'uploaded') { uploadNext(i + 1); return; }
f.status = '0%';
f.status = 'читаю...';
renderTable();
uploadTimer.textContent = 'Загрузка ' + (i+1) + '/' + fileQueue.length + '...';
var xhr = new XMLHttpRequest();
var fd = new FormData();
fd.append('files', f.file);
if (contractId) fd.append('contract_id', contractId);
var reader = new FileReader();
reader.onload = function(e) {
// data:application/pdf;base64,xxxx → xxxx
var b64 = e.target.result.split(',')[1];
var payload = {filename: f.name, data: b64};
if (contractId) payload.contract_id = contractId;
xhr.open('POST', '/upload.cfm');
xhr.timeout = 120000;
xhr.upload.onprogress = function(e) {
if (e.lengthComputable) {
f.status = Math.round(e.loaded / e.total * 100) + '%';
renderTable();
}
};
xhr.onload = function() {
try {
var r = JSON.parse(xhr.responseText);
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 {
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';
log('❌ ' + f.name + ': ' + (r.ERROR || ''));
}
renderTable();
uploadNext(i + 1);
}).catch(function(e) {
f.status = 'error';
log('❌ ' + f.name + ': ' + (r.ERROR || ''));
}
} catch(e) { f.status = 'error'; log('❌ ' + f.name + ': ' + e.message); }
log('❌ ' + f.name + ': ' + e.message);
renderTable();
uploadNext(i + 1);
});
};
reader.onerror = function() {
f.status = 'error';
log('❌ ' + f.name + ': ошибка чтения');
renderTable();
uploadNext(i + 1);
};
xhr.onerror = function() {
f.status = 'error (status=0 — обрыв)';
log('❌ ' + f.name + ': сеть (status=0)');
renderTable();
uploadNext(i + 1);
};
xhr.ontimeout = function() {
f.status = 'error (таймаут)';
log('❌ ' + f.name + ': таймаут 120с');
renderTable();
uploadNext(i + 1);
};
xhr.send(fd);
reader.readAsDataURL(f.file);
}
uploadNext(0);
});