From 99e71134598ddecd0a89b01979151985af832878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Fri, 10 Jul 2026 23:18:23 +0400 Subject: [PATCH] fix: retry 3x per chunk, 300ms delay --- site/static/app.js | 48 +++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/site/static/app.js b/site/static/app.js index 08235e4..b99d95a 100644 --- a/site/static/app.js +++ b/site/static/app.js @@ -214,28 +214,36 @@ async function uploadAll() { fileSummary.textContent = summary; } -/** uploadChunk(blob) — отправить чанк как raw тело */ +/** uploadChunk(blob) — отправить чанк с ретраем до 3 раз */ function uploadChunk(blob) { + var MAX = 3; + var attempt = 0; + return new Promise(function (resolve, reject) { - var xhr = new XMLHttpRequest(); - xhr.open('POST', '/upload'); - xhr.timeout = 10000; - xhr.setRequestHeader('Content-Type', 'application/octet-stream'); - 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('Bad JSON')); - } - }; - xhr.onerror = function () { reject(new Error('Сеть')); }; - xhr.ontimeout = function () { reject(new Error('Таймаут')); }; - xhr.send(blob); + function trySend() { + attempt++; + var xhr = new XMLHttpRequest(); + xhr.open('POST', '/upload'); + xhr.timeout = 5000; + xhr.setRequestHeader('Content-Type', 'application/octet-stream'); + 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('Bad JSON')); } + }; + xhr.onerror = function () { + if (attempt < MAX) { setTimeout(trySend, 300); } + else { reject(new Error('Сеть')); } + }; + xhr.ontimeout = function () { + if (attempt < MAX) { setTimeout(trySend, 300); } + else { reject(new Error('Таймаут')); } + }; + xhr.send(blob); + } + trySend(); }); }