@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.d.cts CHANGED
@@ -278,8 +278,8 @@ interface UploadOptions extends ServerTarget {
278
278
  file: FileSource;
279
279
  /** File lifetime in milliseconds (0 = server default). */
280
280
  lifetimeMs: number;
281
- /** Whether to encrypt the file with E2EE. */
282
- encrypt: boolean;
281
+ /** Whether to encrypt the file with E2EE. Defaults to true if server supports E2EE. */
282
+ encrypt?: boolean;
283
283
  /** Override the filename sent to the server. */
284
284
  filenameOverride?: string;
285
285
  /** Callback for progress updates. */
@@ -328,8 +328,8 @@ interface ValidateUploadOptions {
328
328
  file: FileSource;
329
329
  /** Requested file lifetime in milliseconds. */
330
330
  lifetimeMs: number;
331
- /** Whether encryption will be used. */
332
- encrypt: boolean;
331
+ /** Whether encryption will be used. Defaults to true if server supports E2EE. */
332
+ encrypt?: boolean;
333
333
  /** Server info containing capabilities to validate against. */
334
334
  serverInfo: ServerInfo;
335
335
  }
package/dist/index.d.ts CHANGED
@@ -278,8 +278,8 @@ interface UploadOptions extends ServerTarget {
278
278
  file: FileSource;
279
279
  /** File lifetime in milliseconds (0 = server default). */
280
280
  lifetimeMs: number;
281
- /** Whether to encrypt the file with E2EE. */
282
- encrypt: boolean;
281
+ /** Whether to encrypt the file with E2EE. Defaults to true if server supports E2EE. */
282
+ encrypt?: boolean;
283
283
  /** Override the filename sent to the server. */
284
284
  filenameOverride?: string;
285
285
  /** Callback for progress updates. */
@@ -328,8 +328,8 @@ interface ValidateUploadOptions {
328
328
  file: FileSource;
329
329
  /** Requested file lifetime in milliseconds. */
330
330
  lifetimeMs: number;
331
- /** Whether encryption will be used. */
332
- encrypt: boolean;
331
+ /** Whether encryption will be used. Defaults to true if server supports E2EE. */
332
+ encrypt?: boolean;
333
333
  /** Server info containing capabilities to validate against. */
334
334
  serverInfo: ServerInfo;
335
335
  }
package/dist/index.js CHANGED
@@ -507,7 +507,7 @@ var DropgateClient = class {
507
507
  }
508
508
  if (encrypt && !caps.e2ee) {
509
509
  throw new DropgateValidationError(
510
- "Server does not support end-to-end encryption."
510
+ "End-to-end encryption is not supported on this server."
511
511
  );
512
512
  }
513
513
  return true;
@@ -569,14 +569,16 @@ var DropgateClient = class {
569
569
  throw new DropgateValidationError(compat.message);
570
570
  }
571
571
  const filename = filenameOverride ?? file.name ?? "file";
572
- if (!encrypt) {
572
+ const serverSupportsE2EE = Boolean(serverInfo?.capabilities?.upload?.e2ee);
573
+ const effectiveEncrypt = encrypt ?? serverSupportsE2EE;
574
+ if (!effectiveEncrypt) {
573
575
  validatePlainFilename(filename);
574
576
  }
575
- this.validateUploadInputs({ file, lifetimeMs, encrypt, serverInfo });
577
+ this.validateUploadInputs({ file, lifetimeMs, encrypt: effectiveEncrypt, serverInfo });
576
578
  let cryptoKey = null;
577
579
  let keyB64 = null;
578
580
  let transmittedFilename = filename;
579
- if (encrypt) {
581
+ if (effectiveEncrypt) {
580
582
  progress({ phase: "crypto", text: "Generating encryption key...", percent: 0, processedBytes: 0, totalBytes: fileSizeBytes });
581
583
  try {
582
584
  cryptoKey = await generateAesGcmKey(this.cryptoObj);
@@ -597,13 +599,13 @@ var DropgateClient = class {
597
599
  const totalUploadSize = estimateTotalUploadSizeBytes(
598
600
  file.size,
599
601
  totalChunks,
600
- encrypt
602
+ effectiveEncrypt
601
603
  );
602
604
  progress({ phase: "init", text: "Reserving server storage...", percent: 0, processedBytes: 0, totalBytes: fileSizeBytes });
603
605
  const initPayload = {
604
606
  filename: transmittedFilename,
605
607
  lifetime: lifetimeMs,
606
- isEncrypted: Boolean(encrypt),
608
+ isEncrypted: effectiveEncrypt,
607
609
  totalSize: totalUploadSize,
608
610
  totalChunks
609
611
  };
@@ -657,7 +659,7 @@ var DropgateClient = class {
657
659
  });
658
660
  const chunkBuffer = await chunkBlob.arrayBuffer();
659
661
  let uploadBlob;
660
- if (encrypt && cryptoKey) {
662
+ if (effectiveEncrypt && cryptoKey) {
661
663
  uploadBlob = await encryptToBlob(this.cryptoObj, chunkBuffer, cryptoKey);
662
664
  } else {
663
665
  uploadBlob = new Blob([chunkBuffer]);
@@ -728,7 +730,7 @@ var DropgateClient = class {
728
730
  );
729
731
  }
730
732
  let downloadUrl = `${baseUrl}/${fileId}`;
731
- if (encrypt && keyB64) {
733
+ if (effectiveEncrypt && keyB64) {
732
734
  downloadUrl += `#${keyB64}`;
733
735
  }
734
736
  progress({ phase: "done", text: "Upload successful!", percent: 100, processedBytes: fileSizeBytes, totalBytes: fileSizeBytes });
@@ -738,7 +740,7 @@ var DropgateClient = class {
738
740
  fileId,
739
741
  uploadId,
740
742
  baseUrl,
741
- ...encrypt && keyB64 ? { keyB64 } : {}
743
+ ...effectiveEncrypt && keyB64 ? { keyB64 } : {}
742
744
  };
743
745
  } catch (err) {
744
746
  if (err instanceof Error && (err.name === "AbortError" || err.message?.includes("abort"))) {