From fba3b0ad47ff0096c3834ecbb0e46029eabe7512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Sat, 11 Jul 2026 06:49:20 +0400 Subject: [PATCH] revert: back to baseline (no flow control), bump 1.0.18 --- site/app.py | 3 +-- site/static/app.js | 40 +++++++++++++++++----------------------- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/site/app.py b/site/app.py index 61025c4..9750389 100644 --- a/site/app.py +++ b/site/app.py @@ -22,7 +22,7 @@ def health(): @sock.route('/ws-upload') def ws_upload(ws): - """WebSocket: получает чанки, ACK после каждого, считает байты и время""" + """WebSocket: получает чанки, считает байты и время""" t0 = time.time() total = 0 while True: @@ -32,7 +32,6 @@ def ws_upload(ws): if isinstance(chunk, str) and chunk == 'DONE': break total += len(chunk) - ws.send(json.dumps({'ack': total})) elapsed = round((time.time() - t0) * 1000) ws.send(json.dumps({'ok': True, 'bytes': total, 'elapsed_ms': elapsed})) diff --git a/site/static/app.js b/site/static/app.js index 3120ea3..02e0a50 100644 --- a/site/static/app.js +++ b/site/static/app.js @@ -210,9 +210,20 @@ function uploadFileWS(url, f, idx) { ws.onopen = function () { var reader = new FileReader(); - reader.onload = function (e) { ws.send(e.target.result); + offset += CHUNK; + if (offset < f.size) { + var pct = Math.round(offset / f.size * 100); + if (pct - lastProgress >= 10) { + lastProgress = pct; + f.progress = pct; + renderTable(); + } + readNext(); + } else { + ws.send('DONE'); + } }; function readNext() { var end = Math.min(offset + CHUNK, f.size); @@ -224,28 +235,11 @@ function uploadFileWS(url, f, idx) { ws.onmessage = function (e) { try { var r = JSON.parse(e.data); - if (r.ack) { - // Сервер подтвердил получение N байт - offset = r.ack; - var pct = Math.round(offset / f.size * 100); - if (pct - lastProgress >= 10) { - lastProgress = pct; - f.progress = pct; - renderTable(); - } - if (offset < f.size) { - readNext(); - } else { - ws.send('DONE'); - } - } else if (r.ok) { - // Финальный ответ - clearTimeout(timer); - f.progress = 100; - renderTable(); - ws.close(); - resolve({ bytes: r.bytes, elapsed_ms: Date.now() - startTime }); - } + clearTimeout(timer); + f.progress = 100; + renderTable(); + ws.close(); + resolve({ bytes: r.bytes, elapsed_ms: Date.now() - startTime }); } catch (err) { reject(new Error('Bad response')); }