@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.d.cts CHANGED
@@ -71,6 +71,8 @@ interface UploadCapabilities {
71
71
  maxSizeMB?: number;
72
72
  /** Maximum file lifetime in hours (0 = unlimited). */
73
73
  maxLifetimeHours?: number;
74
+ /** Maximum downloads before file is deleted (0 = unlimited). */
75
+ maxFileDownloads?: number;
74
76
  /** Whether end-to-end encryption is supported. */
75
77
  e2ee?: boolean;
76
78
  }
@@ -278,14 +280,16 @@ interface UploadOptions extends ServerTarget {
278
280
  file: FileSource;
279
281
  /** File lifetime in milliseconds (0 = server default). */
280
282
  lifetimeMs: number;
281
- /** Whether to encrypt the file with E2EE. */
282
- encrypt: boolean;
283
+ /** Whether to encrypt the file with E2EE. Defaults to true if server supports E2EE. */
284
+ encrypt?: boolean;
283
285
  /** Override the filename sent to the server. */
284
286
  filenameOverride?: string;
285
287
  /** Callback for progress updates. */
286
288
  onProgress?: (evt: UploadProgressEvent) => void;
287
289
  /** Callback when upload is cancelled by user. */
288
290
  onCancel?: () => void;
291
+ /** Max downloads before file is deleted (0 = unlimited). */
292
+ maxDownloads?: number;
289
293
  /** AbortSignal to cancel the upload. */
290
294
  signal?: AbortSignal;
291
295
  /** Timeout settings for various upload phases. */
@@ -328,8 +332,8 @@ interface ValidateUploadOptions {
328
332
  file: FileSource;
329
333
  /** Requested file lifetime in milliseconds. */
330
334
  lifetimeMs: number;
331
- /** Whether encryption will be used. */
332
- encrypt: boolean;
335
+ /** Whether encryption will be used. Defaults to true if server supports E2EE. */
336
+ encrypt?: boolean;
333
337
  /** Server info containing capabilities to validate against. */
334
338
  serverInfo: ServerInfo;
335
339
  }
package/dist/index.d.ts CHANGED
@@ -71,6 +71,8 @@ interface UploadCapabilities {
71
71
  maxSizeMB?: number;
72
72
  /** Maximum file lifetime in hours (0 = unlimited). */
73
73
  maxLifetimeHours?: number;
74
+ /** Maximum downloads before file is deleted (0 = unlimited). */
75
+ maxFileDownloads?: number;
74
76
  /** Whether end-to-end encryption is supported. */
75
77
  e2ee?: boolean;
76
78
  }
@@ -278,14 +280,16 @@ interface UploadOptions extends ServerTarget {
278
280
  file: FileSource;
279
281
  /** File lifetime in milliseconds (0 = server default). */
280
282
  lifetimeMs: number;
281
- /** Whether to encrypt the file with E2EE. */
282
- encrypt: boolean;
283
+ /** Whether to encrypt the file with E2EE. Defaults to true if server supports E2EE. */
284
+ encrypt?: boolean;
283
285
  /** Override the filename sent to the server. */
284
286
  filenameOverride?: string;
285
287
  /** Callback for progress updates. */
286
288
  onProgress?: (evt: UploadProgressEvent) => void;
287
289
  /** Callback when upload is cancelled by user. */
288
290
  onCancel?: () => void;
291
+ /** Max downloads before file is deleted (0 = unlimited). */
292
+ maxDownloads?: number;
289
293
  /** AbortSignal to cancel the upload. */
290
294
  signal?: AbortSignal;
291
295
  /** Timeout settings for various upload phases. */
@@ -328,8 +332,8 @@ interface ValidateUploadOptions {
328
332
  file: FileSource;
329
333
  /** Requested file lifetime in milliseconds. */
330
334
  lifetimeMs: number;
331
- /** Whether encryption will be used. */
332
- encrypt: boolean;
335
+ /** Whether encryption will be used. Defaults to true if server supports E2EE. */
336
+ encrypt?: boolean;
333
337
  /** Server info containing capabilities to validate against. */
334
338
  serverInfo: ServerInfo;
335
339
  }
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;
@@ -529,6 +529,7 @@ var DropgateClient = class {
529
529
  file,
530
530
  lifetimeMs,
531
531
  encrypt,
532
+ maxDownloads,
532
533
  filenameOverride,
533
534
  onProgress,
534
535
  onCancel,
@@ -569,14 +570,16 @@ var DropgateClient = class {
569
570
  throw new DropgateValidationError(compat.message);
570
571
  }
571
572
  const filename = filenameOverride ?? file.name ?? "file";
572
- if (!encrypt) {
573
+ const serverSupportsE2EE = Boolean(serverInfo?.capabilities?.upload?.e2ee);
574
+ const effectiveEncrypt = encrypt ?? serverSupportsE2EE;
575
+ if (!effectiveEncrypt) {
573
576
  validatePlainFilename(filename);
574
577
  }
575
- this.validateUploadInputs({ file, lifetimeMs, encrypt, serverInfo });
578
+ this.validateUploadInputs({ file, lifetimeMs, encrypt: effectiveEncrypt, serverInfo });
576
579
  let cryptoKey = null;
577
580
  let keyB64 = null;
578
581
  let transmittedFilename = filename;
579
- if (encrypt) {
582
+ if (effectiveEncrypt) {
580
583
  progress({ phase: "crypto", text: "Generating encryption key...", percent: 0, processedBytes: 0, totalBytes: fileSizeBytes });
581
584
  try {
582
585
  cryptoKey = await generateAesGcmKey(this.cryptoObj);
@@ -597,15 +600,16 @@ var DropgateClient = class {
597
600
  const totalUploadSize = estimateTotalUploadSizeBytes(
598
601
  file.size,
599
602
  totalChunks,
600
- encrypt
603
+ effectiveEncrypt
601
604
  );
602
605
  progress({ phase: "init", text: "Reserving server storage...", percent: 0, processedBytes: 0, totalBytes: fileSizeBytes });
603
606
  const initPayload = {
604
607
  filename: transmittedFilename,
605
608
  lifetime: lifetimeMs,
606
- isEncrypted: Boolean(encrypt),
609
+ isEncrypted: effectiveEncrypt,
607
610
  totalSize: totalUploadSize,
608
- totalChunks
611
+ totalChunks,
612
+ ...maxDownloads !== void 0 ? { maxDownloads } : {}
609
613
  };
610
614
  const initRes = await fetchJson(this.fetchFn, `${baseUrl}/upload/init`, {
611
615
  method: "POST",
@@ -657,7 +661,7 @@ var DropgateClient = class {
657
661
  });
658
662
  const chunkBuffer = await chunkBlob.arrayBuffer();
659
663
  let uploadBlob;
660
- if (encrypt && cryptoKey) {
664
+ if (effectiveEncrypt && cryptoKey) {
661
665
  uploadBlob = await encryptToBlob(this.cryptoObj, chunkBuffer, cryptoKey);
662
666
  } else {
663
667
  uploadBlob = new Blob([chunkBuffer]);
@@ -728,7 +732,7 @@ var DropgateClient = class {
728
732
  );
729
733
  }
730
734
  let downloadUrl = `${baseUrl}/${fileId}`;
731
- if (encrypt && keyB64) {
735
+ if (effectiveEncrypt && keyB64) {
732
736
  downloadUrl += `#${keyB64}`;
733
737
  }
734
738
  progress({ phase: "done", text: "Upload successful!", percent: 100, processedBytes: fileSizeBytes, totalBytes: fileSizeBytes });
@@ -738,7 +742,7 @@ var DropgateClient = class {
738
742
  fileId,
739
743
  uploadId,
740
744
  baseUrl,
741
- ...encrypt && keyB64 ? { keyB64 } : {}
745
+ ...effectiveEncrypt && keyB64 ? { keyB64 } : {}
742
746
  };
743
747
  } catch (err) {
744
748
  if (err instanceof Error && (err.name === "AbortError" || err.message?.includes("abort"))) {