base64 JSON загрузка вместо FormData/multipart — обход лимита Ingress, v1.21
This commit is contained in:
+36
-32
@@ -59,7 +59,7 @@
|
||||
<body>
|
||||
<div class="topbar">
|
||||
<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.20</span></span>
|
||||
<span class="title">Сверка договоров <span style="font-weight:400;color:var(--muted);font-size:12px;">v1.21</span></span>
|
||||
</div>
|
||||
|
||||
<div class="content">
|
||||
@@ -155,24 +155,36 @@
|
||||
|
||||
window.removeFile = removeFile;
|
||||
|
||||
// ── Чанковая загрузка (50KB) ────────────────────────────────
|
||||
// ── Загрузка base64 (JSON) ──────────────────────────────────
|
||||
|
||||
async function uploadFileChunked(file, cid, onProgress) {
|
||||
var CHUNK_SIZE = 50 * 1024;
|
||||
var totalChunks = Math.ceil(file.size / CHUNK_SIZE);
|
||||
var uploadId = file.name + '_' + Date.now() + '_' + Math.random().toString(36).substr(2, 6);
|
||||
var totalSent = 0;
|
||||
var lastResp = null;
|
||||
function readFileAsBase64(file, onProgress) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var reader = new FileReader();
|
||||
reader.onprogress = function(e) {
|
||||
if (e.lengthComputable && onProgress) onProgress(Math.round(e.loaded / e.total * 20));
|
||||
};
|
||||
reader.onload = function() {
|
||||
var b64 = reader.result.split(',')[1];
|
||||
resolve(b64);
|
||||
};
|
||||
reader.onerror = function() { reject(new Error('Read error')); };
|
||||
reader.readAsDataURL(file);
|
||||
});
|
||||
}
|
||||
|
||||
for (var i = 0; i < totalChunks; i++) {
|
||||
var start = i * CHUNK_SIZE;
|
||||
var end = Math.min(start + CHUNK_SIZE, file.size);
|
||||
var chunk = file.slice(start, end);
|
||||
|
||||
var resp = await new Promise(function(resolve, reject) {
|
||||
function uploadFileJSON(file, cid, onProgress) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
readFileAsBase64(file, onProgress).then(function(b64) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', '/chunk');
|
||||
xhr.timeout = 60000;
|
||||
xhr.open('POST', '/upload');
|
||||
xhr.setRequestHeader('Content-Type', 'application/json');
|
||||
xhr.timeout = 120000;
|
||||
|
||||
xhr.upload.onprogress = function(e) {
|
||||
if (e.lengthComputable && onProgress) {
|
||||
onProgress(20 + Math.round(e.loaded / e.total * 80));
|
||||
}
|
||||
};
|
||||
|
||||
xhr.onload = function() {
|
||||
if (xhr.status === 200) {
|
||||
@@ -188,21 +200,13 @@
|
||||
xhr.onerror = function() { reject(new Error('Сеть')); };
|
||||
xhr.ontimeout = function() { reject(new Error('Таймаут')); };
|
||||
|
||||
var fd = new FormData();
|
||||
fd.append('chunk', chunk);
|
||||
fd.append('upload_id', uploadId);
|
||||
fd.append('filename', file.name);
|
||||
fd.append('chunk_index', i);
|
||||
fd.append('total_chunks', totalChunks);
|
||||
if (cid) fd.append('cid', cid);
|
||||
xhr.send(fd);
|
||||
});
|
||||
|
||||
if (resp && resp.contract_id) lastResp = resp;
|
||||
totalSent += (end - start);
|
||||
if (onProgress) onProgress(Math.round(totalSent / file.size * 100));
|
||||
}
|
||||
return lastResp;
|
||||
xhr.send(JSON.stringify({
|
||||
filename: file.name,
|
||||
data: b64,
|
||||
cid: cid || null
|
||||
}));
|
||||
}).catch(reject);
|
||||
});
|
||||
}
|
||||
|
||||
// ── Выбор файла → сразу загрузка ────────────────────────────
|
||||
@@ -226,7 +230,7 @@
|
||||
var startTime = Date.now();
|
||||
|
||||
try {
|
||||
var resp = await uploadFileChunked(f, contractId, function(pct) {
|
||||
var resp = await uploadFileJSON(f, contractId, function(pct) {
|
||||
fileQueue[rowIdx].status = '<span style="color:var(--muted);">↑ ' + pct + '%</span>';
|
||||
renderTable();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user