@arbidocs/react 0.5.109 → 0.5.110

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -3332,13 +3332,18 @@ function useUploadFiles() {
3332
3332
  }
3333
3333
  const total = input.files.reduce((sum, file) => sum + file.size, 0);
3334
3334
  const loadedByBatch = new Array(batches.length).fill(0);
3335
+ const filesByBatch = new Array(batches.length).fill(0);
3335
3336
  let done = 0;
3337
+ let highest = 0;
3336
3338
  const report = () => {
3337
3339
  const loaded = loadedByBatch.reduce((sum, bytes) => sum + bytes, 0);
3340
+ const sent = filesByBatch.reduce((sum, files) => sum + files, 0);
3341
+ const share = input.files.length > 0 ? sent / input.files.length : 0;
3342
+ highest = Math.max(highest, Math.min(Math.round(share * 100), 100));
3338
3343
  onProgress?.({
3339
3344
  loaded,
3340
3345
  total,
3341
- percentage: total > 0 ? Math.min(Math.round(loaded / total * 100), 100) : 0,
3346
+ percentage: highest,
3342
3347
  batches: batches.length > 1 ? { current: done, total: batches.length } : null
3343
3348
  });
3344
3349
  };
@@ -3352,11 +3357,14 @@ function useUploadFiles() {
3352
3357
  configExtId: input.configExtId ?? void 0,
3353
3358
  // Named even when it is the open one: batches sent after a switch stay in this workspace.
3354
3359
  workspaceExtId: workspaceId,
3360
+ // One request for the batch: its files count by the share of its bytes sent.
3355
3361
  onProgress: (loaded) => {
3356
3362
  loadedByBatch[index] = Math.min(loaded, bytes);
3363
+ filesByBatch[index] = bytes > 0 ? loadedByBatch[index] / bytes * files.length : 0;
3357
3364
  report();
3358
3365
  }
3359
3366
  });
3367
+ const fileShares = new Array(files.length).fill(0);
3360
3368
  const directly = async (key, workspace) => arbi.documents.uploadDirect(
3361
3369
  workspace,
3362
3370
  key,
@@ -3371,9 +3379,15 @@ function useUploadFiles() {
3371
3379
  shared: input.shared,
3372
3380
  folder: folder ?? void 0,
3373
3381
  configExtId: input.configExtId ?? void 0,
3374
- // Ciphertext bytes, scaled back to the files' own so the total stays true.
3375
- onBytesProgress: ({ loaded, total: sent }) => {
3376
- loadedByBatch[index] = sent > 0 ? Math.round(loaded / sent * bytes) : 0;
3382
+ // Per file, in ciphertext bytes: that file's share sent, scaled back to its own
3383
+ // size so the byte total stays true.
3384
+ onBytesProgress: ({ fileIndex, loaded, total: sent }) => {
3385
+ const share = sent > 0 ? Math.min(loaded / sent, 1) : 0;
3386
+ fileShares[fileIndex] = Math.max(fileShares[fileIndex] ?? 0, share);
3387
+ loadedByBatch[index] = Math.round(
3388
+ files.reduce((sum, file, i) => sum + (fileShares[i] ?? 0) * file.size, 0)
3389
+ );
3390
+ filesByBatch[index] = fileShares.reduce((sum, part) => sum + part, 0);
3377
3391
  report();
3378
3392
  }
3379
3393
  }
@@ -3390,6 +3404,7 @@ function useUploadFiles() {
3390
3404
  );
3391
3405
  }
3392
3406
  loadedByBatch[index] = bytes;
3407
+ filesByBatch[index] = files.length;
3393
3408
  done += 1;
3394
3409
  report();
3395
3410
  return result;