v1.0.35: iframe + form-encoded base64

This commit is contained in:
2026-06-18 21:26:18 +04:00
parent 0a3ccdb973
commit b2b148c1b7
2 changed files with 75 additions and 35 deletions
+37 -33
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.34 — Lucee</span></span>
<span class="title">Сверка договоров <span style="font-weight:400;color:var(--muted);font-size:12px;">v1.0.35 — Lucee</span></span>
</div>
<div class="content">
@@ -221,7 +221,7 @@ fileInput.addEventListener('change', function() {
renderTable();
});
// ── Загрузка через iframe (отдельный контекст на каждый файл)
// ── Загрузка через iframe (base64 в скрытом поле) ───────
uploadBtn.addEventListener('click', function() {
if (fileQueue.length === 0) return;
uploadBtn.disabled = true;
@@ -231,7 +231,7 @@ uploadBtn.addEventListener('click', function() {
var pending = fileQueue.filter(function(f) { return !f.doc_id; });
var done = 0;
function uploadNext(i) {
function readThenUpload(i) {
if (i >= pending.length) {
uploadTimer.style.display = 'none';
uploadBtn.disabled = false;
@@ -242,18 +242,34 @@ uploadBtn.addEventListener('click', function() {
return;
}
var f = pending[i];
f.status = '0%';
f.status = 'читаю...';
renderTable();
uploadTimer.textContent = 'Загрузка ' + (i+1) + '/' + pending.length;
uploadTimer.textContent = 'Чтение ' + (i+1) + '/' + pending.length;
// Создаём уникальный iframe
var iframeId = 'up_iframe_' + Date.now() + '_' + i;
var reader = new FileReader();
reader.onload = function(e) {
var b64 = e.target.result.split(',')[1];
f.status = '0%';
renderTable();
uploadTimer.textContent = 'Загрузка ' + (i+1) + '/' + pending.length;
submitFile(i, f, b64);
};
reader.onerror = function() {
f.status = 'error: чтение';
renderTable();
readThenUpload(i + 1);
};
reader.readAsDataURL(f.file);
}
function submitFile(i, f, b64) {
var iframe = document.createElement('iframe');
iframe.name = iframeId;
iframe.name = 'upfrm_' + Date.now() + '_' + i;
iframe.style.display = 'none';
iframe.onload = function() {
try {
var resp = iframe.contentDocument.body.textContent;
var resp = iframe.contentDocument.body.textContent.trim();
if (!resp) { throw new Error('пустой ответ'); }
var r = JSON.parse(resp);
if (r.OK) {
contractId = r.CONTRACT_ID;
@@ -272,38 +288,26 @@ uploadBtn.addEventListener('click', function() {
}
renderTable();
document.body.removeChild(iframe);
uploadNext(i + 1);
readThenUpload(i + 1);
};
document.body.appendChild(iframe);
// Форма внутри iframe
var form = iframe.contentDocument.createElement('form');
// Форма с скрытыми полями, target = iframe
var form = document.createElement('form');
form.method = 'POST';
form.action = '/upload.cfm';
form.enctype = 'multipart/form-data';
var input = iframe.contentDocument.createElement('input');
input.type = 'file';
input.name = 'files';
// Копируем файл в форму через DataTransfer
var dt = new DataTransfer();
dt.items.add(f.file);
input.files = dt.files;
form.appendChild(input);
if (contractId) {
var cidInput = iframe.contentDocument.createElement('input');
cidInput.type = 'hidden';
cidInput.name = 'contract_id';
cidInput.value = contractId;
form.appendChild(cidInput);
}
iframe.contentDocument.body.appendChild(form);
form.target = iframe.name;
form.style.display = 'none';
form.innerHTML =
'<input type="hidden" name="filename" value="' + f.name.replace(/"/g,'&quot;') + '">' +
'<input type="hidden" name="data" value="' + b64.replace(/"/g,'&quot;') + '">' +
(contractId ? '<input type="hidden" name="contract_id" value="' + contractId + '">' : '');
document.body.appendChild(form);
form.submit();
setTimeout(function() { document.body.removeChild(form); }, 100);
}
uploadNext(0);
readThenUpload(0);
});
// ── Инфо ──────────────────────────────────────────────────