diff options
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/static/app.js')
| -rw-r--r-- | packages/meshbay-hub/src/meshbay_hub/static/app.js | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/app.js b/packages/meshbay-hub/src/meshbay_hub/static/app.js index fee21dc..3ef0da5 100644 --- a/packages/meshbay-hub/src/meshbay_hub/static/app.js +++ b/packages/meshbay-hub/src/meshbay_hub/static/app.js @@ -832,7 +832,6 @@ function formatDate(ts) { // ── Group Page ────────────────────────────────────────────────────────────── const CHUNK_SIZE = 1024 * 1024; -const UPLOAD_CHUNK_SIZE = 48 * 1024; const PIPELINE_WINDOW = 8; async function pipelinedDownload(transport, gekKey, fileId, totalChunks, onChunk, writable) { @@ -1109,15 +1108,10 @@ function GroupPage({ groupId, group, token, username, userId, onRefreshAuth, setError(''); setUlState({ name: file.name, sent: 0, total: file.size, indexing: false }); try { - const totalChunks = Math.ceil(file.size / UPLOAD_CHUNK_SIZE); - for (let i = 0; i < totalChunks; i++) { - const slice = file.slice(i * UPLOAD_CHUNK_SIZE, (i + 1) * UPLOAD_CHUNK_SIZE); - const buf = new Uint8Array(await slice.arrayBuffer()); - await transport.uploadChunk(file.name, i, totalChunks, buf); + await transport.uploadFile(file, { // Bytes actually acknowledged by the node, not bytes read locally. - setUlState(prev => prev && { ...prev, sent: Math.min(file.size, - (i + 1) * UPLOAD_CHUNK_SIZE) }); - } + onProgress: (sent) => setUlState(prev => prev && { ...prev, sent }), + }); // The node re-indexes on a filesystem event; there is nothing to poll, so // say what is happening instead of showing a finished bar and no file. setUlState(prev => prev && { ...prev, indexing: true }); @@ -1934,16 +1928,10 @@ function ChatPanel({ transportRef, username, entries, gekRef, onRefreshIndex, on if (!transport || !transport.connected) return; setAttaching(true); try { - const totalChunks = Math.ceil(file.size / UPLOAD_CHUNK_SIZE); - let storedAs = file.name; - for (let i = 0; i < totalChunks; i++) { - const slice = file.slice(i * UPLOAD_CHUNK_SIZE, (i + 1) * UPLOAD_CHUNK_SIZE); - const buf = new Uint8Array(await slice.arrayBuffer()); - const ack = await transport.uploadChunk(file.name, i, totalChunks, buf); - // Two people sending IMG_1234.jpg both succeed; the node picks a free - // name and the message has to point at the one it chose. - if (ack && ack.stored_as) storedAs = ack.stored_as; - } + // Two people sending IMG_1234.jpg both succeed; the node picks a free name + // and the message has to point at the one it chose. + const ack = await transport.uploadFile(file); + const storedAs = (ack && ack.stored_as) || file.name; await new Promise(r => setTimeout(r, 2500)); if (onRefreshIndex) await onRefreshIndex(); const ext = file.name.split('.').pop().toLowerCase(); |