v1.0.34: iframe-загрузка — обход HTTP/2 multiplexing
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.33 — Lucee</span></span>
|
<span class="title">Сверка договоров <span style="font-weight:400;color:var(--muted);font-size:12px;">v1.0.34 — Lucee</span></span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
@@ -221,7 +221,7 @@ fileInput.addEventListener('change', function() {
|
|||||||
renderTable();
|
renderTable();
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── Загрузка (читаем все → шлём одним JSON) ────────────
|
// ── Загрузка через iframe (отдельный контекст на каждый файл) ─
|
||||||
uploadBtn.addEventListener('click', function() {
|
uploadBtn.addEventListener('click', function() {
|
||||||
if (fileQueue.length === 0) return;
|
if (fileQueue.length === 0) return;
|
||||||
uploadBtn.disabled = true;
|
uploadBtn.disabled = true;
|
||||||
@@ -229,77 +229,81 @@ uploadBtn.addEventListener('click', function() {
|
|||||||
uploadTimer.style.display = 'block';
|
uploadTimer.style.display = 'block';
|
||||||
|
|
||||||
var pending = fileQueue.filter(function(f) { return !f.doc_id; });
|
var pending = fileQueue.filter(function(f) { return !f.doc_id; });
|
||||||
var payloads = [];
|
var done = 0;
|
||||||
var readIdx = 0;
|
|
||||||
|
|
||||||
function readAll() {
|
function uploadNext(i) {
|
||||||
if (readIdx >= pending.length) { sendAll(); return; }
|
if (i >= pending.length) {
|
||||||
var f = pending[readIdx];
|
|
||||||
f.status = 'читаю...';
|
|
||||||
renderTable();
|
|
||||||
var reader = new FileReader();
|
|
||||||
reader.onload = function(e) {
|
|
||||||
payloads.push({filename: f.name, data: e.target.result.split(',')[1]});
|
|
||||||
readIdx++;
|
|
||||||
uploadTimer.textContent = 'Чтение ' + readIdx + '/' + pending.length;
|
|
||||||
readAll();
|
|
||||||
};
|
|
||||||
reader.onerror = function() {
|
|
||||||
f.status = 'error: чтение';
|
|
||||||
renderTable();
|
|
||||||
readIdx++;
|
|
||||||
readAll();
|
|
||||||
};
|
|
||||||
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;
|
if (contractId && done === pending.length) {
|
||||||
}
|
|
||||||
uploadTimer.textContent = 'Отправка...';
|
|
||||||
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) {
|
|
||||||
contractId = data.CONTRACT_ID || contractId;
|
|
||||||
for (var i = 0; i < pending.length; i++) {
|
|
||||||
pending[i].status = 'uploaded';
|
|
||||||
}
|
|
||||||
var elapsed = ((Date.now() - uploadStartTime) / 1000).toFixed(1);
|
|
||||||
log('✅ ' + pending.length + ' файлов — ' + elapsed + 'с');
|
|
||||||
} else {
|
|
||||||
for (var i = 0; i < pending.length; i++) {
|
|
||||||
pending[i].status = 'error: ' + (data.ERROR || 'неизв.');
|
|
||||||
}
|
|
||||||
log('❌ ' + (data.ERROR || 'неизв.'));
|
|
||||||
}
|
|
||||||
renderTable();
|
|
||||||
if (contractId) {
|
|
||||||
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 = pending[i];
|
||||||
for (var i = 0; i < pending.length; i++) {
|
f.status = '0%';
|
||||||
pending[i].status = 'error: ' + e.message;
|
renderTable();
|
||||||
|
uploadTimer.textContent = 'Загрузка ' + (i+1) + '/' + pending.length;
|
||||||
|
|
||||||
|
// Создаём уникальный iframe
|
||||||
|
var iframeId = 'up_iframe_' + Date.now() + '_' + i;
|
||||||
|
var iframe = document.createElement('iframe');
|
||||||
|
iframe.name = iframeId;
|
||||||
|
iframe.style.display = 'none';
|
||||||
|
iframe.onload = function() {
|
||||||
|
try {
|
||||||
|
var resp = iframe.contentDocument.body.textContent;
|
||||||
|
var r = JSON.parse(resp);
|
||||||
|
if (r.OK) {
|
||||||
|
contractId = r.CONTRACT_ID;
|
||||||
|
f.doc_id = r.DOC_ID;
|
||||||
|
f.status = 'uploaded';
|
||||||
|
done++;
|
||||||
|
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 || ''));
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
f.status = 'error: ' + e.message;
|
||||||
|
log('❌ ' + f.name + ': ' + e.message);
|
||||||
}
|
}
|
||||||
renderTable();
|
renderTable();
|
||||||
});
|
document.body.removeChild(iframe);
|
||||||
|
uploadNext(i + 1);
|
||||||
|
};
|
||||||
|
document.body.appendChild(iframe);
|
||||||
|
|
||||||
|
// Форма внутри iframe
|
||||||
|
var form = iframe.contentDocument.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);
|
||||||
}
|
}
|
||||||
|
|
||||||
readAll();
|
iframe.contentDocument.body.appendChild(form);
|
||||||
|
form.submit();
|
||||||
|
}
|
||||||
|
|
||||||
|
uploadNext(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── Инфо ──────────────────────────────────────────────────
|
// ── Инфо ──────────────────────────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user