@dropgate/core 2.2.0-beta.1 → 2.2.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.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;
@@ -598,6 +598,7 @@ var DropgateClient = class {
598
598
  file,
599
599
  lifetimeMs,
600
600
  encrypt,
601
+ maxDownloads,
601
602
  filenameOverride,
602
603
  onProgress,
603
604
  onCancel,
@@ -638,14 +639,16 @@ var DropgateClient = class {
638
639
  throw new DropgateValidationError(compat.message);
639
640
  }
640
641
  const filename = filenameOverride ?? file.name ?? "file";
641
- if (!encrypt) {
642
+ const serverSupportsE2EE = Boolean(serverInfo?.capabilities?.upload?.e2ee);
643
+ const effectiveEncrypt = encrypt ?? serverSupportsE2EE;
644
+ if (!effectiveEncrypt) {
642
645
  validatePlainFilename(filename);
643
646
  }
644
- this.validateUploadInputs({ file, lifetimeMs, encrypt, serverInfo });
647
+ this.validateUploadInputs({ file, lifetimeMs, encrypt: effectiveEncrypt, serverInfo });
645
648
  let cryptoKey = null;
646
649
  let keyB64 = null;
647
650
  let transmittedFilename = filename;
648
- if (encrypt) {
651
+ if (effectiveEncrypt) {
649
652
  progress({ phase: "crypto", text: "Generating encryption key...", percent: 0, processedBytes: 0, totalBytes: fileSizeBytes });
650
653
  try {
651
654
  cryptoKey = await generateAesGcmKey(this.cryptoObj);
@@ -666,15 +669,16 @@ var DropgateClient = class {
666
669
  const totalUploadSize = estimateTotalUploadSizeBytes(
667
670
  file.size,
668
671
  totalChunks,
669
- encrypt
672
+ effectiveEncrypt
670
673
  );
671
674
  progress({ phase: "init", text: "Reserving server storage...", percent: 0, processedBytes: 0, totalBytes: fileSizeBytes });
672
675
  const initPayload = {
673
676
  filename: transmittedFilename,
674
677
  lifetime: lifetimeMs,
675
- isEncrypted: Boolean(encrypt),
678
+ isEncrypted: effectiveEncrypt,
676
679
  totalSize: totalUploadSize,
677
- totalChunks
680
+ totalChunks,
681
+ ...maxDownloads !== void 0 ? { maxDownloads } : {}
678
682
  };
679
683
  const initRes = await fetchJson(this.fetchFn, `${baseUrl}/upload/init`, {
680
684
  method: "POST",
@@ -726,7 +730,7 @@ var DropgateClient = class {
726
730
  });
727
731
  const chunkBuffer = await chunkBlob.arrayBuffer();
728
732
  let uploadBlob;
729
- if (encrypt && cryptoKey) {
733
+ if (effectiveEncrypt && cryptoKey) {
730
734
  uploadBlob = await encryptToBlob(this.cryptoObj, chunkBuffer, cryptoKey);
731
735
  } else {
732
736
  uploadBlob = new Blob([chunkBuffer]);
@@ -797,7 +801,7 @@ var DropgateClient = class {
797
801
  );
798
802
  }
799
803
  let downloadUrl = `${baseUrl}/${fileId}`;
800
- if (encrypt && keyB64) {
804
+ if (effectiveEncrypt && keyB64) {
801
805
  downloadUrl += `#${keyB64}`;
802
806
  }
803
807
  progress({ phase: "done", text: "Upload successful!", percent: 100, processedBytes: fileSizeBytes, totalBytes: fileSizeBytes });
@@ -807,7 +811,7 @@ var DropgateClient = class {
807
811
  fileId,
808
812
  uploadId,
809
813
  baseUrl,
810
- ...encrypt && keyB64 ? { keyB64 } : {}
814
+ ...effectiveEncrypt && keyB64 ? { keyB64 } : {}
811
815
  };
812
816
  } catch (err) {
813
817
  if (err instanceof Error && (err.name === "AbortError" || err.message?.includes("abort"))) {