v1.0.37: загрузка через прокси contracts.kube5s.ru/lucee/
This commit is contained in:
@@ -65,7 +65,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.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>
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
@@ -222,9 +222,8 @@ fileInput.addEventListener('change', function() {
|
|||||||
renderTable();
|
renderTable();
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── Загрузка чанками (8KB) ────────────────────────────────
|
// ── Загрузка через прокси (contracts.kube5s.ru/lucee/) ──
|
||||||
var CHUNK_SIZE = 8000;
|
var UPLOAD_URL = 'https://contracts.kube5s.ru/lucee/upload.cfm';
|
||||||
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);}); }
|
|
||||||
|
|
||||||
uploadBtn.addEventListener('click', function() {
|
uploadBtn.addEventListener('click', function() {
|
||||||
if (fileQueue.length === 0) return;
|
if (fileQueue.length === 0) return;
|
||||||
@@ -232,10 +231,8 @@ uploadBtn.addEventListener('click', function() {
|
|||||||
uploadStartTime = Date.now();
|
uploadStartTime = Date.now();
|
||||||
uploadTimer.style.display = 'block';
|
uploadTimer.style.display = 'block';
|
||||||
|
|
||||||
var pending = fileQueue.filter(function(f) { return !f.doc_id; });
|
function uploadNext(i) {
|
||||||
|
if (i >= fileQueue.length) {
|
||||||
function processNext(i) {
|
|
||||||
if (i >= pending.length) {
|
|
||||||
uploadTimer.style.display = 'none';
|
uploadTimer.style.display = 'none';
|
||||||
uploadBtn.disabled = false;
|
uploadBtn.disabled = false;
|
||||||
var hasErrors = fileQueue.some(function(f) { return f.status && f.status.indexOf('error') === 0; });
|
var hasErrors = fileQueue.some(function(f) { return f.status && f.status.indexOf('error') === 0; });
|
||||||
@@ -245,58 +242,59 @@ uploadBtn.addEventListener('click', function() {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var f = pending[i];
|
var f = fileQueue[i];
|
||||||
f.status = 'читаю...';
|
if (f.doc_id) { uploadNext(i + 1); return; }
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function sendChunks(f, b64, i, pending) {
|
f.status = '0%';
|
||||||
var chunks = [];
|
renderTable();
|
||||||
for (var p = 0; p < b64.length; p += CHUNK_SIZE) chunks.push(b64.substring(p, p + CHUNK_SIZE));
|
uploadTimer.textContent = 'Загрузка ' + (i+1) + '/' + fileQueue.length;
|
||||||
var uploadId = uuid();
|
|
||||||
var ok = true;
|
var xhr = new XMLHttpRequest();
|
||||||
for (var ci = 0; ci < chunks.length; ci++) {
|
var fd = new FormData();
|
||||||
try {
|
fd.append('files', f.file);
|
||||||
var resp = await fetch('/chunk.cfm?action=put', {
|
if (contractId) fd.append('contract_id', contractId);
|
||||||
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||''})
|
xhr.open('POST', UPLOAD_URL);
|
||||||
});
|
xhr.timeout = 180000;
|
||||||
var d = await resp.json();
|
xhr.upload.onprogress = function(e) {
|
||||||
if (!d.OK) { ok = false; log('❌ ' + f.name + ' чанк ' + ci + ': ' + d.ERROR); break; }
|
if (e.lengthComputable) {
|
||||||
f.status = Math.round((ci+1)/chunks.length*100) + '%';
|
f.status = Math.round(e.loaded / e.total * 100) + '%';
|
||||||
renderTable();
|
renderTable();
|
||||||
uploadTimer.textContent = f.name + ' ' + f.status;
|
|
||||||
} catch(e) { ok = false; f.status = 'error: ' + e.message; renderTable(); break; }
|
|
||||||
}
|
}
|
||||||
if (ok) {
|
};
|
||||||
|
xhr.onload = function() {
|
||||||
try {
|
try {
|
||||||
var resp = await fetch('/chunk.cfm?action=assemble', {
|
var r = JSON.parse(xhr.responseText);
|
||||||
method: 'POST', headers: {'Content-Type':'application/json'},
|
if (r.OK) {
|
||||||
body: JSON.stringify({upload_id:uploadId})
|
contractId = r.CONTRACT_ID;
|
||||||
});
|
f.doc_id = r.DOC_ID;
|
||||||
var d = await resp.json();
|
|
||||||
if (d.OK) {
|
|
||||||
contractId = d.CONTRACT_ID || contractId;
|
|
||||||
f.doc_id = d.DOC_ID;
|
|
||||||
f.status = 'uploaded';
|
f.status = 'uploaded';
|
||||||
var elapsed = ((Date.now() - uploadStartTime) / 1000).toFixed(1);
|
var elapsed = ((Date.now() - uploadStartTime) / 1000).toFixed(1);
|
||||||
log('✅ ' + f.name + ' (' + formatSize(f.size) + ') — ' + elapsed + 'с');
|
log('✅ ' + f.name + ' (' + formatSize(f.size) + ') — ' + elapsed + 'с');
|
||||||
} else { f.status = 'error: ' + (d.ERROR||''); log('❌ ' + f.name + ': ' + (d.ERROR||'')); }
|
} else {
|
||||||
} catch(e) { f.status = 'error: ' + e.message; log('❌ ' + f.name + ': ' + e.message); }
|
f.status = 'error: ' + (r.ERROR || 'неизв.');
|
||||||
|
log('❌ ' + f.name + ': ' + (r.ERROR || ''));
|
||||||
}
|
}
|
||||||
|
} catch(e) { f.status = 'error: ' + e.message; log('❌ ' + f.name + ': ' + e.message); }
|
||||||
renderTable();
|
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);
|
||||||
});
|
});
|
||||||
|
|
||||||
// ── Инфо ──────────────────────────────────────────────────
|
// ── Инфо ──────────────────────────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user