v1.0.37: загрузка через прокси contracts.kube5s.ru/lucee/

This commit is contained in:
2026-06-19 07:04:52 +04:00
parent a23ea0f049
commit e2334d6ca7
+47 -49
View File
@@ -65,7 +65,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.36 — Lucee</span></span>
<span class="title">Сверка договоров <span style="font-weight:400;color:var(--muted);font-size:12px;">v1.0.37 — Lucee</span></span>
</div>
<div class="content">
@@ -222,9 +222,8 @@ fileInput.addEventListener('change', function() {
renderTable();
});
// ── Загрузка чанками (8KB) ────────────────────────────────
var CHUNK_SIZE = 8000;
function uuid() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,function(c){var r=Math.random()*16|0,v=c=='x'?r:(r&3|8);return v.toString(16);}); }
// ── Загрузка через прокси (contracts.kube5s.ru/lucee/) ──
var UPLOAD_URL = 'https://contracts.kube5s.ru/lucee/upload.cfm';
uploadBtn.addEventListener('click', function() {
if (fileQueue.length === 0) return;
@@ -232,10 +231,8 @@ uploadBtn.addEventListener('click', function() {
uploadStartTime = Date.now();
uploadTimer.style.display = 'block';
var pending = fileQueue.filter(function(f) { return !f.doc_id; });
function processNext(i) {
if (i >= pending.length) {
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; });
@@ -245,58 +242,59 @@ uploadBtn.addEventListener('click', function() {
}
return;
}
var f = pending[i];
f.status = 'читаю...';
renderTable();
uploadTimer.textContent = 'Файл ' + (i+1) + '/' + pending.length;
var reader = new FileReader();
reader.onload = function(e) {
var b64 = e.target.result.split(',')[1];
sendChunks(f, b64, i, pending);
};
reader.onerror = function() { f.status = 'error: чтение'; renderTable(); processNext(i+1); };
reader.readAsDataURL(f.file);
}
var f = fileQueue[i];
if (f.doc_id) { uploadNext(i + 1); return; }
async function sendChunks(f, b64, i, pending) {
var chunks = [];
for (var p = 0; p < b64.length; p += CHUNK_SIZE) chunks.push(b64.substring(p, p + CHUNK_SIZE));
var uploadId = uuid();
var ok = true;
for (var ci = 0; ci < chunks.length; ci++) {
try {
var resp = await fetch('/chunk.cfm?action=put', {
method: 'POST', headers: {'Content-Type':'application/json'},
body: JSON.stringify({upload_id:uploadId, chunk_index:ci, total_chunks:chunks.length, filename:f.name, data:chunks[ci], contract_id:contractId||''})
});
var d = await resp.json();
if (!d.OK) { ok = false; log('❌ ' + f.name + ' чанк ' + ci + ': ' + d.ERROR); break; }
f.status = Math.round((ci+1)/chunks.length*100) + '%';
f.status = '0%';
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);
xhr.open('POST', UPLOAD_URL);
xhr.timeout = 180000;
xhr.upload.onprogress = function(e) {
if (e.lengthComputable) {
f.status = Math.round(e.loaded / e.total * 100) + '%';
renderTable();
uploadTimer.textContent = f.name + ' ' + f.status;
} catch(e) { ok = false; f.status = 'error: ' + e.message; renderTable(); break; }
}
if (ok) {
};
xhr.onload = function() {
try {
var resp = await fetch('/chunk.cfm?action=assemble', {
method: 'POST', headers: {'Content-Type':'application/json'},
body: JSON.stringify({upload_id:uploadId})
});
var d = await resp.json();
if (d.OK) {
contractId = d.CONTRACT_ID || contractId;
f.doc_id = d.DOC_ID;
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 { f.status = 'error: ' + (d.ERROR||''); log('❌ ' + f.name + ': ' + (d.ERROR||'')); }
} catch(e) { f.status = 'error: ' + e.message; log('❌ ' + f.name + ': ' + e.message); }
} else {
f.status = 'error: ' + (r.ERROR || 'неизв.');
log('❌ ' + f.name + ': ' + (r.ERROR || ''));
}
} catch(e) { f.status = 'error: ' + e.message; log('❌ ' + f.name + ': ' + e.message); }
renderTable();
processNext(i + 1);
uploadNext(i + 1);
};
xhr.onerror = function() {
f.status = 'error: сеть';
log('❌ ' + f.name + ': сеть');
renderTable();
uploadNext(i + 1);
};
xhr.ontimeout = function() {
f.status = 'error: таймаут';
log('❌ ' + f.name + ': таймаут');
renderTable();
uploadNext(i + 1);
};
xhr.send(fd);
}
processNext(0);
uploadNext(0);
});
// ── Инфо ──────────────────────────────────────────────────