deepspace 0.19.5 → 0.20.0

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.js CHANGED
@@ -3548,13 +3548,13 @@ var MAX_UPLOAD_REQUEST_BYTES = 25 * 1024 * 1024;
3548
3548
  var UPLOAD_PART_BYTES = 20 * 1024 * 1024;
3549
3549
  var MAX_UPLOAD_PARTS = Math.ceil(MAX_APP_FILE_BYTES / UPLOAD_PART_BYTES);
3550
3550
  var MAX_BASE64_UPLOAD_BYTES = Math.floor(MAX_UPLOAD_REQUEST_BYTES * 3 / 4);
3551
- function planUploadParts(totalBytes, partSize) {
3551
+ function planUploadParts(totalBytes) {
3552
3552
  const parts = [];
3553
- for (let start = 0; start < totalBytes; start += partSize) {
3553
+ for (let start = 0; start < totalBytes; start += UPLOAD_PART_BYTES) {
3554
3554
  parts.push({
3555
3555
  partNumber: parts.length + 1,
3556
3556
  start,
3557
- end: Math.min(start + partSize, totalBytes)
3557
+ end: Math.min(start + UPLOAD_PART_BYTES, totalBytes)
3558
3558
  });
3559
3559
  }
3560
3560
  return parts;
@@ -3630,21 +3630,35 @@ function resolveFile(fileOrKey) {
3630
3630
  async function uploadInParts(file, name, scopeParams, authHeaders, onProgress) {
3631
3631
  const headers = await authHeaders();
3632
3632
  const json = { ...headers, "Content-Type": "application/json" };
3633
- const initResponse = await fetch(`/api/files/multipart?${scopeParams}`, {
3633
+ const requestId = crypto.randomUUID();
3634
+ const initBody = JSON.stringify({
3635
+ requestId,
3636
+ name,
3637
+ mimeType: file.type || "application/octet-stream",
3638
+ size: file.size
3639
+ });
3640
+ const sendInit = () => fetch(`/api/files/multipart?${scopeParams}`, {
3634
3641
  method: "POST",
3635
3642
  headers: json,
3636
- body: JSON.stringify({ name, mimeType: file.type || "application/octet-stream", size: file.size })
3643
+ body: initBody
3637
3644
  });
3645
+ let initResponse = await sendInit().catch(() => null);
3646
+ if (!initResponse || initResponse.status === 429 || initResponse.status >= 500) {
3647
+ initResponse = await sendInit().catch(() => null);
3648
+ }
3649
+ if (!initResponse) {
3650
+ return { success: false, error: "The files service could not be reached." };
3651
+ }
3638
3652
  if (!initResponse.ok) return await readUploadResult(initResponse);
3639
3653
  const session = await initResponse.json();
3640
- if (!Number.isSafeInteger(session.partSize) || session.partSize < 1) {
3654
+ if (!session.uploadId || !session.uploadKey || !session.reservationId || session.partSize !== UPLOAD_PART_BYTES) {
3641
3655
  return {
3642
3656
  success: false,
3643
- error: `The files service advertised an unusable part size (${session.partSize}).`
3657
+ error: `The files service returned an unusable part size or multipart session (${session.partSize}).`
3644
3658
  };
3645
3659
  }
3646
- const query = `${scopeParams}&uploadKey=${encodeKeyPath(session.uploadKey)}&uploadId=${encodeURIComponent(session.uploadId)}`;
3647
- const plan = planUploadParts(file.size, session.partSize);
3660
+ const query = `${scopeParams}&uploadKey=${encodeKeyPath(session.uploadKey)}&uploadId=${encodeURIComponent(session.uploadId)}&reservationId=${encodeURIComponent(session.reservationId)}`;
3661
+ const plan = planUploadParts(file.size);
3648
3662
  const parts = [];
3649
3663
  let assembled = false;
3650
3664
  try {
@@ -3727,10 +3741,7 @@ function useR2Files(options) {
3727
3741
  async (base64Data, name, mimeType) => {
3728
3742
  setIsUploading(true);
3729
3743
  try {
3730
- const tooBig = oversize(
3731
- Math.floor(base64Data.length * 3 / 4),
3732
- MAX_BASE64_UPLOAD_BYTES
3733
- );
3744
+ const tooBig = oversize(Math.floor(base64Data.length * 3 / 4), MAX_BASE64_UPLOAD_BYTES);
3734
3745
  if (tooBig) return tooBig;
3735
3746
  const headers = await authHeaders();
3736
3747
  const response = await fetch(`/api/files/upload?${scopeParams}`, {