убраны ретраи, чистый XHR, v1.39
This commit is contained in:
+26
-40
@@ -59,7 +59,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<div class="topbar">
|
<div class="topbar">
|
||||||
<img src="{{ url_for('static', filename='nubes-logo.svg') }}" alt="Nubes">
|
<img src="{{ url_for('static', filename='nubes-logo.svg') }}" alt="Nubes">
|
||||||
<span class="title">Сверка договоров <span style="font-weight:400;color:var(--muted);font-size:12px;">v1.38</span></span>
|
<span class="title">Сверка договоров <span style="font-weight:400;color:var(--muted);font-size:12px;">v1.39</span></span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
@@ -155,47 +155,33 @@
|
|||||||
|
|
||||||
window.removeFile = removeFile;
|
window.removeFile = removeFile;
|
||||||
|
|
||||||
// ── Загрузка base64 (JSON, с повторами) ──────────────────
|
// ── Загрузка base64 (JSON) ──────────────────────────────────
|
||||||
|
|
||||||
function uploadFileJSON(file, cid, onProgress) {
|
function uploadFileJSON(file, cid, onProgress) {
|
||||||
var b64 = null;
|
return new Promise(function(resolve, reject) {
|
||||||
|
var reader = new FileReader();
|
||||||
function tryUpload(attempt) {
|
reader.onload = function() {
|
||||||
return new Promise(function(resolve, reject) {
|
var b64 = reader.result.split(',')[1];
|
||||||
function doSend() {
|
var xhr = new XMLHttpRequest();
|
||||||
var xhr = new XMLHttpRequest();
|
xhr.open('POST', '/upload');
|
||||||
xhr.open('POST', '/upload');
|
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
xhr.timeout = 30000;
|
||||||
xhr.timeout = 120000;
|
xhr.upload.onprogress = function(e) {
|
||||||
xhr.upload.onprogress = function(e) {
|
if (e.lengthComputable && onProgress) onProgress(Math.round(e.loaded / e.total * 100));
|
||||||
if (e.lengthComputable && onProgress) onProgress(Math.round(e.loaded / e.total * 100));
|
};
|
||||||
};
|
xhr.onload = function() {
|
||||||
xhr.onload = function() {
|
if (xhr.status === 200) {
|
||||||
if (xhr.status === 200) {
|
try { resolve(JSON.parse(xhr.responseText)); }
|
||||||
try { resolve(JSON.parse(xhr.responseText)); }
|
catch(e) { reject(new Error('Bad JSON')); }
|
||||||
catch(e) { reject(new Error('Bad JSON')); }
|
} else { reject(new Error('HTTP ' + xhr.status)); }
|
||||||
} else { reject(new Error('HTTP ' + xhr.status)); }
|
};
|
||||||
};
|
xhr.onerror = function() { reject(new Error('Сеть')); };
|
||||||
xhr.onerror = function() { reject(new Error('Сеть')); };
|
xhr.ontimeout = function() { reject(new Error('Таймаут')); };
|
||||||
xhr.ontimeout = function() { reject(new Error('Таймаут')); };
|
xhr.send(JSON.stringify({filename: file.name, data: b64, cid: cid || null}));
|
||||||
xhr.send(JSON.stringify({filename: file.name, data: b64, cid: cid || null}));
|
};
|
||||||
}
|
reader.onerror = function() { reject(new Error('Read error')); };
|
||||||
|
reader.readAsDataURL(file);
|
||||||
if (b64) { doSend(); return; }
|
});
|
||||||
var reader = new FileReader();
|
|
||||||
reader.onload = function() { b64 = reader.result.split(',')[1]; doSend(); };
|
|
||||||
reader.onerror = function() { reject(new Error('Read error')); };
|
|
||||||
reader.readAsDataURL(file);
|
|
||||||
}).catch(function(err) {
|
|
||||||
if (attempt < 3) {
|
|
||||||
return new Promise(function(r) { setTimeout(r, 1000); }).then(function() {
|
|
||||||
return tryUpload(attempt + 1);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
throw err;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return tryUpload(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Выбор файла → сразу загрузка ────────────────────────────
|
// ── Выбор файла → сразу загрузка ────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user