feat: base64-режим загрузки (обход DDOS-Guard), v1.0.3
Deploy loadtest / validate (push) Waiting to run

This commit is contained in:
2026-07-10 09:00:02 +04:00
parent 25c0b17f91
commit 699a73d48d
2 changed files with 60 additions and 33 deletions
+48 -32
View File
@@ -180,48 +180,64 @@ async function uploadAll() {
fileSummary.textContent = summary;
}
/** uploadOne(fileEntry, idx) — XHR одного файла, возвращает {bytes, elapsed_ms} */
/** uploadOne(fileEntry, idx) — читает файл в base64, отправляет как поле формы */
function uploadOne(f, idx) {
return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
var fd = new FormData();
fd.append('file', f.file, f.name);
// Шаг 1: прочитать файл в base64
f.status = 'uploading';
f.progress = 0;
renderTable();
var t0 = Date.now();
var reader = new FileReader();
reader.onload = function () {
// base64-строка готова, теперь отправляем
var t0 = Date.now();
var xhr = new XMLHttpRequest();
var fd = new FormData();
fd.append('data', reader.result);
fd.append('name', f.name);
fd.append('orig_size', f.size);
xhr.open('POST', '/upload');
xhr.open('POST', '/upload');
xhr.upload.onprogress = function (e) {
if (e.lengthComputable) {
f.progress = Math.round(e.loaded / e.total * 100);
renderTable();
}
};
xhr.onload = function () {
try {
var r = JSON.parse(xhr.responseText);
if (r.ok) {
resolve({ bytes: r.bytes, elapsed_ms: r.elapsed_ms });
} else {
reject(new Error(r.error || 'Ошибка сервера'));
xhr.upload.onprogress = function (e) {
if (e.lengthComputable) {
f.progress = Math.round(e.loaded / e.total * 100);
renderTable();
}
} catch (e) {
reject(new Error('Некорректный ответ'));
}
};
xhr.onload = function () {
try {
var r = JSON.parse(xhr.responseText);
if (r.ok) {
resolve({ bytes: r.bytes, elapsed_ms: r.elapsed_ms });
} else {
reject(new Error(r.error || 'Ошибка сервера'));
}
} catch (e) {
reject(new Error('Некорректный ответ'));
}
};
xhr.onerror = function () {
var elapsed = Date.now() - t0;
reject(new Error('Сеть (' + (elapsed / 1000).toFixed(0) + 'с)'));
};
xhr.ontimeout = function () {
reject(new Error('Таймаут (' + (xhr.timeout / 1000) + 'с)'));
};
xhr.timeout = 600000; // 10 минут (base64 +33%)
xhr.send(fd);
};
xhr.onerror = function () {
var elapsed = Date.now() - t0;
reject(new Error('Сеть (' + (elapsed / 1000).toFixed(0) + 'с)'));
reader.onerror = function () {
reject(new Error('Ошибка чтения файла'));
};
xhr.ontimeout = function () {
reject(new Error('Таймаут (' + (xhr.timeout / 1000) + 'с)'));
};
xhr.timeout = 300000; // 5 минут на файл
xhr.send(fd);
reader.readAsDataURL(f.file);
});
}