diff options
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/static/transport.js')
| -rw-r--r-- | packages/meshbay-hub/src/meshbay_hub/static/transport.js | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/transport.js b/packages/meshbay-hub/src/meshbay_hub/static/transport.js index 1f05b8d..77bf522 100644 --- a/packages/meshbay-hub/src/meshbay_hub/static/transport.js +++ b/packages/meshbay-hub/src/meshbay_hub/static/transport.js @@ -2329,15 +2329,17 @@ class MeshBayTransport { async uploadFile(file, { chunkSize, onProgress, signal, root, dir, tr = '' } = {}) { // The same file twice at once would confuse the node, which keys its own - // upload state by name — and would race for the same destination. The guard - // is by name for that reason, even though the map below is keyed by id. - if (this._inFlightUploads.has(file.name)) { + // upload state by folder and name — and would race for the same + // destination. The guard uses the same key: by name alone, a dropped folder + // holding a `cover.jpg` in two albums failed the second one for nothing. + const inFlightKey = `${dir || ''}/${file.name}`; + if (this._inFlightUploads.has(inFlightKey)) { throw new Error(`${file.name} is already being uploaded`); } if (!this._gekRaw) throw new Error('This group has no key on this device'); const C = window.MeshBayCrypto; const groupId = (this._connectArgs && this._connectArgs.groupId) || ''; - this._inFlightUploads.add(file.name); + this._inFlightUploads.add(inFlightKey); const uploadId = _hex(crypto.getRandomValues(new Uint8Array(16))); const size = chunkSize || UPLOAD_CHUNK_SIZE; const total = Math.max(1, Math.ceil(file.size / size)); @@ -2487,7 +2489,7 @@ class MeshBayTransport { } } finally { this._uploaders.delete(uploadId); - this._inFlightUploads.delete(file.name); + this._inFlightUploads.delete(inFlightKey); } return stored || {}; } |