diff --git a/index.cfm b/index.cfm
index 3143f44..f72206d 100644
--- a/index.cfm
+++ b/index.cfm
@@ -64,7 +64,7 @@

-
Сверка договоров v1.0.24 — Lucee
+
Сверка договоров v1.0.25 — Lucee
@@ -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);
});
diff --git a/upload.cfm b/upload.cfm
index 564cfa5..2cbaaad 100644
--- a/upload.cfm
+++ b/upload.cfm
@@ -13,68 +13,82 @@
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+ #serializeJSON(result)#
+
-
+
+
+
+
+
-
-
-
- INSERT INTO documents (filename, mime_type, original_bytes, status)
- VALUES (
- ,
- ,
- ,
- 'uploaded'
- )
-
-
-
- SELECT id FROM documents
- WHERE filename =
- AND status = 'uploaded'
- ORDER BY created_at DESC LIMIT 1
-
-
-
-
-
-
-
-
- INSERT INTO contracts (number, client) VALUES (
- ,
- ''
- )
-
-
- SELECT id FROM contracts ORDER BY created_at DESC LIMIT 1
-
-
-
-
-
- INSERT INTO supplements (contract_id, document_id, type) VALUES (
- ,
- ,
-
- )
-
-
-
-
+
+
+
+ #serializeJSON(result)#
+
+
+
+
+
+
+
+
+
+
+
+
+
+ INSERT INTO documents (filename, mime_type, original_bytes, status)
+ VALUES (
+ ,
+ ,
+ ,
+ 'uploaded'
+ )
+
+
+ SELECT id FROM documents
+ WHERE filename =
+ AND status = 'uploaded' ORDER BY created_at DESC LIMIT 1
+
+
+
+
+
+
+ INSERT INTO contracts (number, client) VALUES (
+ , ''
+ )
+
+
+ SELECT id FROM contracts ORDER BY created_at DESC LIMIT 1
+
+
+
+
+ INSERT INTO supplements (contract_id, document_id, type) VALUES (
+ ,
+ ,
+
+ )
+
+
+
+