@dropgate/core 2.2.0-beta.1 → 2.2.0-beta.2

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
@@ -576,7 +576,7 @@ var DropgateClient = class {
576
576
  }
577
577
  if (encrypt && !caps.e2ee) {
578
578
  throw new DropgateValidationError(
579
- "Server does not support end-to-end encryption."
579
+ "End-to-end encryption is not supported on this server."
580
580
  );
581
581
  }
582
582
  return true;
@@ -638,14 +638,16 @@ var DropgateClient = class {
638
638
  throw new DropgateValidationError(compat.message);
639
639
  }
640
640
  const filename = filenameOverride ?? file.name ?? "file";
641
- if (!encrypt) {
641
+ const serverSupportsE2EE = Boolean(serverInfo?.capabilities?.upload?.e2ee);
642
+ const effectiveEncrypt = encrypt ?? serverSupportsE2EE;
643
+ if (!effectiveEncrypt) {
642
644
  validatePlainFilename(filename);
643
645
  }
644
- this.validateUploadInputs({ file, lifetimeMs, encrypt, serverInfo });
646
+ this.validateUploadInputs({ file, lifetimeMs, encrypt: effectiveEncrypt, serverInfo });
645
647
  let cryptoKey = null;
646
648
  let keyB64 = null;
647
649
  let transmittedFilename = filename;
648
- if (encrypt) {
650
+ if (effectiveEncrypt) {
649
651
  progress({ phase: "crypto", text: "Generating encryption key...", percent: 0, processedBytes: 0, totalBytes: fileSizeBytes });
650
652
  try {
651
653
  cryptoKey = await generateAesGcmKey(this.cryptoObj);
@@ -666,13 +668,13 @@ var DropgateClient = class {
666
668
  const totalUploadSize = estimateTotalUploadSizeBytes(
667
669
  file.size,
668
670
  totalChunks,
669
- encrypt
671
+ effectiveEncrypt
670
672
  );
671
673
  progress({ phase: "init", text: "Reserving server storage...", percent: 0, processedBytes: 0, totalBytes: fileSizeBytes });
672
674
  const initPayload = {
673
675
  filename: transmittedFilename,
674
676
  lifetime: lifetimeMs,
675
- isEncrypted: Boolean(encrypt),
677
+ isEncrypted: effectiveEncrypt,
676
678
  totalSize: totalUploadSize,
677
679
  totalChunks
678
680
  };
@@ -726,7 +728,7 @@ var DropgateClient = class {
726
728
  });
727
729
  const chunkBuffer = await chunkBlob.arrayBuffer();
728
730
  let uploadBlob;
729
- if (encrypt && cryptoKey) {
731
+ if (effectiveEncrypt && cryptoKey) {
730
732
  uploadBlob = await encryptToBlob(this.cryptoObj, chunkBuffer, cryptoKey);
731
733
  } else {
732
734
  uploadBlob = new Blob([chunkBuffer]);
@@ -797,7 +799,7 @@ var DropgateClient = class {
797
799
  );
798
800
  }
799
801
  let downloadUrl = `${baseUrl}/${fileId}`;
800
- if (encrypt && keyB64) {
802
+ if (effectiveEncrypt && keyB64) {
801
803
  downloadUrl += `#${keyB64}`;
802
804
  }
803
805
  progress({ phase: "done", text: "Upload successful!", percent: 100, processedBytes: fileSizeBytes, totalBytes: fileSizeBytes });
@@ -807,7 +809,7 @@ var DropgateClient = class {
807
809
  fileId,
808
810
  uploadId,
809
811
  baseUrl,
810
- ...encrypt && keyB64 ? { keyB64 } : {}
812
+ ...effectiveEncrypt && keyB64 ? { keyB64 } : {}
811
813
  };
812
814
  } catch (err) {
813
815
  if (err instanceof Error && (err.name === "AbortError" || err.message?.includes("abort"))) {