@dropgate/core 2.2.1 → 3.0.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/README.md +259 -128
- package/dist/index.browser.js +1 -1
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +2814 -1436
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +424 -283
- package/dist/index.d.ts +424 -283
- package/dist/index.js +2816 -1389
- package/dist/index.js.map +1 -1
- package/dist/p2p/index.cjs +495 -190
- package/dist/p2p/index.cjs.map +1 -1
- package/dist/p2p/index.d.cts +366 -5
- package/dist/p2p/index.d.ts +366 -5
- package/dist/p2p/index.js +497 -178
- package/dist/p2p/index.js.map +1 -1
- package/package.json +15 -12
package/dist/index.d.cts
CHANGED
|
@@ -75,6 +75,8 @@ interface UploadCapabilities {
|
|
|
75
75
|
maxFileDownloads?: number;
|
|
76
76
|
/** Whether end-to-end encryption is supported. */
|
|
77
77
|
e2ee?: boolean;
|
|
78
|
+
/** Expected upload chunk size in bytes (server-configured). */
|
|
79
|
+
chunkSize?: number;
|
|
78
80
|
}
|
|
79
81
|
/**
|
|
80
82
|
* Server P2P (direct transfer) capabilities.
|
|
@@ -133,9 +135,15 @@ interface BaseProgressEvent {
|
|
|
133
135
|
*/
|
|
134
136
|
interface UploadProgressEvent extends BaseProgressEvent {
|
|
135
137
|
/** Current phase of the operation. */
|
|
136
|
-
phase: 'server-info' | 'server-compat' | 'crypto' | 'init' | 'chunk' | 'complete' | 'done' | 'retry-wait' | 'retry';
|
|
138
|
+
phase: 'server-info' | 'server-compat' | 'crypto' | 'init' | 'file-start' | 'chunk' | 'file-complete' | 'complete' | 'done' | 'retry-wait' | 'retry';
|
|
137
139
|
/** Human-readable status text. */
|
|
138
140
|
text?: string;
|
|
141
|
+
/** Index of the current file being uploaded (0-based). Only present for multi-file uploads. */
|
|
142
|
+
fileIndex?: number;
|
|
143
|
+
/** Total number of files being uploaded. Only present for multi-file uploads. */
|
|
144
|
+
totalFiles?: number;
|
|
145
|
+
/** Name of the current file being uploaded. Only present for multi-file uploads. */
|
|
146
|
+
currentFileName?: string;
|
|
139
147
|
/** Current chunk index (0-based). */
|
|
140
148
|
chunkIndex?: number;
|
|
141
149
|
/** Total number of chunks. */
|
|
@@ -147,18 +155,26 @@ interface UploadProgressEvent extends BaseProgressEvent {
|
|
|
147
155
|
interface UploadResult {
|
|
148
156
|
/** Full download URL including encryption key fragment if encrypted. */
|
|
149
157
|
downloadUrl: string;
|
|
150
|
-
/** Unique file identifier on the server. */
|
|
151
|
-
fileId
|
|
152
|
-
/**
|
|
153
|
-
|
|
158
|
+
/** Unique file identifier on the server (set for single-file uploads). */
|
|
159
|
+
fileId?: string;
|
|
160
|
+
/** Unique bundle identifier on the server (set for multi-file uploads). */
|
|
161
|
+
bundleId?: string;
|
|
162
|
+
/** Upload session identifier (set for single-file uploads). */
|
|
163
|
+
uploadId?: string;
|
|
154
164
|
/** Server base URL used for the upload. */
|
|
155
165
|
baseUrl: string;
|
|
156
166
|
/** Base64-encoded encryption key (only present if encrypted). */
|
|
157
167
|
keyB64?: string;
|
|
168
|
+
/** Per-file results (only present for multi-file uploads). */
|
|
169
|
+
files?: Array<{
|
|
170
|
+
fileId: string;
|
|
171
|
+
name: string;
|
|
172
|
+
size: number;
|
|
173
|
+
}>;
|
|
158
174
|
}
|
|
159
175
|
/**
|
|
160
176
|
* Upload session with cancellation support.
|
|
161
|
-
* Returned by
|
|
177
|
+
* Returned by uploadFiles() to allow cancelling uploads in progress.
|
|
162
178
|
*/
|
|
163
179
|
interface UploadSession {
|
|
164
180
|
/** Promise that resolves with upload result when complete. */
|
|
@@ -237,19 +253,16 @@ interface FileSource {
|
|
|
237
253
|
/** Read the entire file as an ArrayBuffer. */
|
|
238
254
|
arrayBuffer(): Promise<ArrayBuffer>;
|
|
239
255
|
}
|
|
240
|
-
/**
|
|
241
|
-
* Logger function type for debug and diagnostic output.
|
|
242
|
-
* @param level - Log level (debug, info, warn, error).
|
|
243
|
-
* @param message - Log message.
|
|
244
|
-
* @param meta - Optional metadata object.
|
|
245
|
-
*/
|
|
246
|
-
type LoggerFn = (level: 'debug' | 'info' | 'warn' | 'error', message: string, meta?: unknown) => void;
|
|
247
256
|
/**
|
|
248
257
|
* Options for constructing a DropgateClient instance.
|
|
249
258
|
*/
|
|
250
259
|
interface DropgateClientOptions {
|
|
251
260
|
/** Client version string for compatibility checking with the server. */
|
|
252
261
|
clientVersion: string;
|
|
262
|
+
/** Server URL string (e.g. 'https://dropgate.link') or ServerTarget object. Required. */
|
|
263
|
+
server: string | ServerTarget;
|
|
264
|
+
/** If true, automatically retry with HTTP when HTTPS connection fails in connect(). Default: false. */
|
|
265
|
+
fallbackToHttp?: boolean;
|
|
253
266
|
/** Upload chunk size in bytes (default: 5MB). */
|
|
254
267
|
chunkSize?: number;
|
|
255
268
|
/** Custom fetch implementation (uses global fetch by default). */
|
|
@@ -258,8 +271,6 @@ interface DropgateClientOptions {
|
|
|
258
271
|
cryptoObj?: CryptoAdapter;
|
|
259
272
|
/** Custom base64 encoder/decoder. */
|
|
260
273
|
base64?: Base64Adapter;
|
|
261
|
-
/** Custom logger function for debug output. */
|
|
262
|
-
logger?: LoggerFn;
|
|
263
274
|
}
|
|
264
275
|
/**
|
|
265
276
|
* Common server target options specifying the server to connect to.
|
|
@@ -273,22 +284,24 @@ interface ServerTarget {
|
|
|
273
284
|
secure?: boolean;
|
|
274
285
|
}
|
|
275
286
|
/**
|
|
276
|
-
* Options for uploading
|
|
287
|
+
* Options for uploading one or more files to the server.
|
|
288
|
+
* Single files use the standard upload protocol. Multiple files use the bundle protocol.
|
|
289
|
+
* Server connection is configured once in the DropgateClient constructor.
|
|
277
290
|
*/
|
|
278
|
-
interface
|
|
279
|
-
/** File to upload. */
|
|
280
|
-
|
|
291
|
+
interface UploadFilesOptions {
|
|
292
|
+
/** File(s) to upload. A single FileSource or an array of FileSources. */
|
|
293
|
+
files: FileSource | FileSource[];
|
|
281
294
|
/** File lifetime in milliseconds (0 = server default). */
|
|
282
295
|
lifetimeMs: number;
|
|
283
|
-
/** Whether to encrypt the file with E2EE. Defaults to true if server supports E2EE. */
|
|
296
|
+
/** Whether to encrypt the file(s) with E2EE. Defaults to true if server supports E2EE. */
|
|
284
297
|
encrypt?: boolean;
|
|
285
|
-
/** Override
|
|
286
|
-
|
|
298
|
+
/** Override filenames sent to the server, keyed by file index. */
|
|
299
|
+
filenameOverrides?: Record<number, string>;
|
|
287
300
|
/** Callback for progress updates. */
|
|
288
301
|
onProgress?: (evt: UploadProgressEvent) => void;
|
|
289
302
|
/** Callback when upload is cancelled by user. */
|
|
290
303
|
onCancel?: () => void;
|
|
291
|
-
/** Max downloads before file is deleted (0 = unlimited). */
|
|
304
|
+
/** Max downloads before file/bundle is deleted (0 = unlimited). */
|
|
292
305
|
maxDownloads?: number;
|
|
293
306
|
/** AbortSignal to cancel the upload. */
|
|
294
307
|
signal?: AbortSignal;
|
|
@@ -316,7 +329,9 @@ interface UploadOptions extends ServerTarget {
|
|
|
316
329
|
/**
|
|
317
330
|
* Options for fetching server information.
|
|
318
331
|
*/
|
|
319
|
-
interface GetServerInfoOptions
|
|
332
|
+
interface GetServerInfoOptions {
|
|
333
|
+
/** Server URL string (e.g. 'https://dropgate.link') or ServerTarget object. */
|
|
334
|
+
server: string | ServerTarget;
|
|
320
335
|
/** Request timeout in milliseconds (default: 5000ms). */
|
|
321
336
|
timeoutMs?: number;
|
|
322
337
|
/** AbortSignal to cancel the request. */
|
|
@@ -324,12 +339,21 @@ interface GetServerInfoOptions extends ServerTarget {
|
|
|
324
339
|
/** Custom fetch implementation (uses global fetch by default). */
|
|
325
340
|
fetchFn?: FetchFn;
|
|
326
341
|
}
|
|
342
|
+
/**
|
|
343
|
+
* Options for the connect() method on DropgateClient.
|
|
344
|
+
*/
|
|
345
|
+
interface ConnectOptions {
|
|
346
|
+
/** Request timeout in milliseconds (default: 5000ms). */
|
|
347
|
+
timeoutMs?: number;
|
|
348
|
+
/** AbortSignal to cancel the request. */
|
|
349
|
+
signal?: AbortSignal;
|
|
350
|
+
}
|
|
327
351
|
/**
|
|
328
352
|
* Options for validating upload inputs before starting an upload.
|
|
329
353
|
*/
|
|
330
354
|
interface ValidateUploadOptions {
|
|
331
|
-
/** File to validate. */
|
|
332
|
-
|
|
355
|
+
/** File(s) to validate. */
|
|
356
|
+
files: FileSource | FileSource[];
|
|
333
357
|
/** Requested file lifetime in milliseconds. */
|
|
334
358
|
lifetimeMs: number;
|
|
335
359
|
/** Whether encryption will be used. Defaults to true if server supports E2EE. */
|
|
@@ -355,22 +379,49 @@ interface FileMetadata {
|
|
|
355
379
|
*/
|
|
356
380
|
interface DownloadProgressEvent extends BaseProgressEvent {
|
|
357
381
|
/** Current phase of the download. */
|
|
358
|
-
phase: 'server-info' | 'server-compat' | 'metadata' | 'downloading' | 'decrypting' | 'complete';
|
|
382
|
+
phase: 'server-info' | 'server-compat' | 'metadata' | 'downloading' | 'decrypting' | 'zipping' | 'complete';
|
|
359
383
|
/** Human-readable status text. */
|
|
360
384
|
text?: string;
|
|
385
|
+
/** Index of the current file being downloaded (0-based). Only present for bundle downloads. */
|
|
386
|
+
fileIndex?: number;
|
|
387
|
+
/** Total number of files in the bundle. Only present for bundle downloads. */
|
|
388
|
+
totalFiles?: number;
|
|
389
|
+
/** Name of the current file being downloaded. Only present for bundle downloads. */
|
|
390
|
+
currentFileName?: string;
|
|
361
391
|
}
|
|
362
392
|
/**
|
|
363
|
-
* Options for downloading
|
|
393
|
+
* Options for downloading one or more files.
|
|
394
|
+
* Use `fileId` for single-file downloads or `bundleId` for multi-file bundle downloads.
|
|
395
|
+
* Server connection is configured once in the DropgateClient constructor.
|
|
364
396
|
*/
|
|
365
|
-
interface
|
|
366
|
-
/** File ID to download. */
|
|
367
|
-
fileId
|
|
368
|
-
/**
|
|
397
|
+
interface DownloadFilesOptions {
|
|
398
|
+
/** File ID to download (for single-file downloads). */
|
|
399
|
+
fileId?: string;
|
|
400
|
+
/** Bundle ID to download (for multi-file bundle downloads). */
|
|
401
|
+
bundleId?: string;
|
|
402
|
+
/** Base64-encoded decryption key (required for encrypted files/bundles). */
|
|
369
403
|
keyB64?: string;
|
|
404
|
+
/** If true and bundleId is set, streams all files as a single ZIP via onData. */
|
|
405
|
+
asZip?: boolean;
|
|
406
|
+
/** Filename for the generated ZIP (default: "dropgate-bundle.zip"). Only used with asZip. */
|
|
407
|
+
zipFilename?: string;
|
|
370
408
|
/** Callback for progress updates. */
|
|
371
409
|
onProgress?: (evt: DownloadProgressEvent) => void;
|
|
372
|
-
/** Callback for received data chunks. Consumer handles
|
|
410
|
+
/** Callback for received data chunks (single-file or ZIP stream). Consumer handles writing. */
|
|
373
411
|
onData?: (chunk: Uint8Array) => Promise<void> | void;
|
|
412
|
+
/** Callback when a file download begins (bundle non-ZIP mode). Consumer opens a new write stream. */
|
|
413
|
+
onFileStart?: (file: {
|
|
414
|
+
name: string;
|
|
415
|
+
size: number;
|
|
416
|
+
index: number;
|
|
417
|
+
}) => void;
|
|
418
|
+
/** Callback for received data chunks per file (bundle non-ZIP mode). */
|
|
419
|
+
onFileData?: (chunk: Uint8Array) => Promise<void> | void;
|
|
420
|
+
/** Callback when a file download ends (bundle non-ZIP mode). Consumer closes the write stream. */
|
|
421
|
+
onFileEnd?: (file: {
|
|
422
|
+
name: string;
|
|
423
|
+
index: number;
|
|
424
|
+
}) => void;
|
|
374
425
|
/** AbortSignal to cancel the download. */
|
|
375
426
|
signal?: AbortSignal;
|
|
376
427
|
/** Request timeout in milliseconds (default: 60000ms). */
|
|
@@ -380,15 +431,43 @@ interface DownloadOptions extends ServerTarget {
|
|
|
380
431
|
* Result of a file download.
|
|
381
432
|
*/
|
|
382
433
|
interface DownloadResult {
|
|
383
|
-
/** Decrypted filename. */
|
|
384
|
-
filename
|
|
385
|
-
/**
|
|
434
|
+
/** Decrypted filename (for single-file downloads). */
|
|
435
|
+
filename?: string;
|
|
436
|
+
/** Decrypted filenames (for bundle downloads). */
|
|
437
|
+
filenames?: string[];
|
|
438
|
+
/** Total bytes received across all files. */
|
|
386
439
|
receivedBytes: number;
|
|
387
|
-
/** Whether the file
|
|
440
|
+
/** Whether the file(s) were encrypted. */
|
|
388
441
|
wasEncrypted: boolean;
|
|
389
|
-
/** The file data (only
|
|
442
|
+
/** The file data (only for small single files when onData callback was not provided). */
|
|
390
443
|
data?: Uint8Array;
|
|
391
444
|
}
|
|
445
|
+
/**
|
|
446
|
+
* Bundle metadata returned from the server.
|
|
447
|
+
*/
|
|
448
|
+
interface BundleMetadata {
|
|
449
|
+
/** Whether the bundle files are encrypted. */
|
|
450
|
+
isEncrypted: boolean;
|
|
451
|
+
/** Total size of all files in bytes. */
|
|
452
|
+
totalSizeBytes: number;
|
|
453
|
+
/** Number of files in the bundle. */
|
|
454
|
+
fileCount: number;
|
|
455
|
+
/** Whether the bundle manifest is encrypted (sealed). Only the downloader can read the file list. */
|
|
456
|
+
sealed?: boolean;
|
|
457
|
+
/** Base64-encoded encrypted manifest blob (only present for sealed bundles). */
|
|
458
|
+
encryptedManifest?: string;
|
|
459
|
+
/** Individual file metadata entries. Populated from server for unsealed bundles, or from decrypted manifest for sealed bundles. */
|
|
460
|
+
files: Array<{
|
|
461
|
+
/** File ID for downloading this individual file. */
|
|
462
|
+
fileId: string;
|
|
463
|
+
/** File size in bytes (encrypted size if encrypted). */
|
|
464
|
+
sizeBytes: number;
|
|
465
|
+
/** Original filename (only for unencrypted files). */
|
|
466
|
+
filename?: string;
|
|
467
|
+
/** Encrypted filename (only for encrypted files). */
|
|
468
|
+
encryptedFilename?: string;
|
|
469
|
+
}>;
|
|
470
|
+
}
|
|
392
471
|
|
|
393
472
|
/**
|
|
394
473
|
* Convert a Uint8Array to a base64 string
|
|
@@ -490,6 +569,10 @@ declare function decryptFilenameFromBase64(cryptoObj: CryptoAdapter, encryptedFi
|
|
|
490
569
|
|
|
491
570
|
/**
|
|
492
571
|
* Compute SHA-256 hash of data and return as hex string.
|
|
572
|
+
*
|
|
573
|
+
* Uses crypto.subtle when available. Falls back to a pure-JS
|
|
574
|
+
* implementation for integrity hashing on insecure contexts.
|
|
575
|
+
* The fallback MUST NOT be used for encryption operations.
|
|
493
576
|
*/
|
|
494
577
|
declare function sha256Hex(cryptoObj: CryptoAdapter, data: ArrayBuffer): Promise<string>;
|
|
495
578
|
/**
|
|
@@ -512,125 +595,48 @@ declare function encryptToBlob(cryptoObj: CryptoAdapter, dataBuffer: ArrayBuffer
|
|
|
512
595
|
declare function encryptFilenameToBase64(cryptoObj: CryptoAdapter, filename: string, key: CryptoKey): Promise<string>;
|
|
513
596
|
|
|
514
597
|
/**
|
|
515
|
-
*
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
baseUrl: string;
|
|
527
|
-
serverInfo: ServerInfo;
|
|
528
|
-
}>;
|
|
529
|
-
/**
|
|
530
|
-
* Headless, environment-agnostic client for Dropgate file uploads.
|
|
531
|
-
* Handles server communication, encryption, and chunked uploads.
|
|
532
|
-
*/
|
|
533
|
-
declare class DropgateClient {
|
|
534
|
-
/** Client version string for compatibility checking. */
|
|
535
|
-
readonly clientVersion: string;
|
|
536
|
-
/** Chunk size in bytes for upload splitting. */
|
|
537
|
-
readonly chunkSize: number;
|
|
538
|
-
/** Fetch implementation used for HTTP requests. */
|
|
539
|
-
readonly fetchFn: FetchFn;
|
|
540
|
-
/** Crypto implementation for encryption operations. */
|
|
541
|
-
readonly cryptoObj: CryptoAdapter;
|
|
542
|
-
/** Base64 encoder/decoder for binary data. */
|
|
543
|
-
readonly base64: Base64Adapter;
|
|
544
|
-
/** Optional logger for debug output. */
|
|
545
|
-
readonly logger: LoggerFn | null;
|
|
546
|
-
/**
|
|
547
|
-
* Create a new DropgateClient instance.
|
|
548
|
-
* @param opts - Client configuration options.
|
|
549
|
-
* @throws {DropgateValidationError} If clientVersion is missing or invalid.
|
|
550
|
-
*/
|
|
551
|
-
constructor(opts: DropgateClientOptions);
|
|
552
|
-
/**
|
|
553
|
-
* Resolve a user-entered sharing code or URL via the server.
|
|
554
|
-
* @param value - The sharing code or URL to resolve.
|
|
555
|
-
* @param opts - Server target and request options.
|
|
556
|
-
* @returns The resolved share target information.
|
|
557
|
-
* @throws {DropgateProtocolError} If the share lookup fails.
|
|
558
|
-
*/
|
|
559
|
-
resolveShareTarget(value: string, opts: GetServerInfoOptions): Promise<ShareTargetResult>;
|
|
598
|
+
* Streaming ZIP writer that assembles files into a ZIP archive on the fly.
|
|
599
|
+
* Uses fflate's store mode (no compression) for maximum speed and minimal memory usage.
|
|
600
|
+
* Works in both Node.js and browser environments.
|
|
601
|
+
*/
|
|
602
|
+
declare class StreamingZipWriter {
|
|
603
|
+
private zip;
|
|
604
|
+
private currentFile;
|
|
605
|
+
private onData;
|
|
606
|
+
private finalized;
|
|
607
|
+
private pendingWrites;
|
|
608
|
+
constructor(onData: (chunk: Uint8Array) => void | Promise<void>);
|
|
560
609
|
/**
|
|
561
|
-
*
|
|
562
|
-
*
|
|
563
|
-
* @param
|
|
564
|
-
* @returns Compatibility result with status, message, and server info.
|
|
565
|
-
* @throws {DropgateNetworkError} If the server cannot be reached.
|
|
566
|
-
* @throws {DropgateProtocolError} If the server returns an invalid response.
|
|
610
|
+
* Begin a new file entry in the ZIP.
|
|
611
|
+
* Must call endFile() before starting another file.
|
|
612
|
+
* @param name - Filename within the ZIP archive.
|
|
567
613
|
*/
|
|
568
|
-
|
|
569
|
-
serverInfo: ServerInfo;
|
|
570
|
-
baseUrl: string;
|
|
571
|
-
}>;
|
|
614
|
+
startFile(name: string): void;
|
|
572
615
|
/**
|
|
573
|
-
*
|
|
574
|
-
* @param
|
|
575
|
-
* @returns True if validation passes.
|
|
576
|
-
* @throws {DropgateValidationError} If any validation check fails.
|
|
616
|
+
* Write a chunk of data to the current file entry.
|
|
617
|
+
* @param data - The data chunk to write.
|
|
577
618
|
*/
|
|
578
|
-
|
|
619
|
+
writeChunk(data: Uint8Array): void;
|
|
579
620
|
/**
|
|
580
|
-
*
|
|
581
|
-
* @param opts - Upload options including file, server target, and settings.
|
|
582
|
-
* @returns Upload result containing the download URL and file identifiers.
|
|
583
|
-
* @throws {DropgateValidationError} If input validation fails.
|
|
584
|
-
* @throws {DropgateNetworkError} If the server cannot be reached.
|
|
585
|
-
* @throws {DropgateProtocolError} If the server returns an error.
|
|
586
|
-
* @throws {DropgateAbortError} If the upload is cancelled.
|
|
621
|
+
* End the current file entry.
|
|
587
622
|
*/
|
|
588
|
-
|
|
623
|
+
endFile(): void;
|
|
589
624
|
/**
|
|
590
|
-
*
|
|
591
|
-
*
|
|
592
|
-
* **Important:** For large files, you must provide an `onData` callback to stream
|
|
593
|
-
* data incrementally. Without it, the entire file is buffered in memory, which will
|
|
594
|
-
* cause memory exhaustion for large files. Files exceeding 100MB without an `onData`
|
|
595
|
-
* callback will throw a validation error.
|
|
596
|
-
*
|
|
597
|
-
* @param opts - Download options including file ID, server target, and optional key.
|
|
598
|
-
* @param opts.onData - Streaming callback that receives data chunks. Required for files > 100MB.
|
|
599
|
-
* @returns Download result containing filename and received bytes.
|
|
600
|
-
* @throws {DropgateValidationError} If input validation fails or file is too large without onData.
|
|
601
|
-
* @throws {DropgateNetworkError} If the server cannot be reached.
|
|
602
|
-
* @throws {DropgateProtocolError} If the server returns an error.
|
|
603
|
-
* @throws {DropgateAbortError} If the download is cancelled.
|
|
625
|
+
* Finalize the ZIP archive. Must be called after all files are written.
|
|
626
|
+
* Waits for all pending async writes to complete before resolving.
|
|
604
627
|
*/
|
|
605
|
-
|
|
606
|
-
private attemptChunkUpload;
|
|
628
|
+
finalize(): Promise<void>;
|
|
607
629
|
}
|
|
608
630
|
|
|
609
|
-
/**
|
|
610
|
-
* Get the default Base64 adapter for the current environment.
|
|
611
|
-
* Automatically detects Node.js Buffer vs browser btoa/atob.
|
|
612
|
-
*/
|
|
613
|
-
declare function getDefaultBase64(): Base64Adapter;
|
|
614
|
-
/**
|
|
615
|
-
* Get the default crypto object for the current environment.
|
|
616
|
-
* Returns globalThis.crypto if available.
|
|
617
|
-
*/
|
|
618
|
-
declare function getDefaultCrypto(): CryptoAdapter | undefined;
|
|
619
|
-
/**
|
|
620
|
-
* Get the default fetch function for the current environment.
|
|
621
|
-
* Returns globalThis.fetch if available.
|
|
622
|
-
*/
|
|
623
|
-
declare function getDefaultFetch(): FetchFn | undefined;
|
|
624
|
-
|
|
625
631
|
/**
|
|
626
632
|
* Finite state machine states for P2P send sessions.
|
|
627
633
|
* Prevents race conditions and ensures callbacks fire in correct order.
|
|
628
634
|
*/
|
|
629
|
-
type P2PSendState = 'initializing' | 'listening' | 'negotiating' | 'transferring' | 'finishing' | 'completed' | 'cancelled' | 'closed';
|
|
635
|
+
type P2PSendState = 'initializing' | 'listening' | 'handshaking' | 'negotiating' | 'transferring' | 'finishing' | 'awaiting_ack' | 'completed' | 'cancelled' | 'closed';
|
|
630
636
|
/**
|
|
631
637
|
* Finite state machine states for P2P receive sessions.
|
|
632
638
|
*/
|
|
633
|
-
type P2PReceiveState = 'initializing' | 'connecting' | 'negotiating' | 'transferring' | 'completed' | 'cancelled' | 'closed';
|
|
639
|
+
type P2PReceiveState = 'initializing' | 'connecting' | 'handshaking' | 'negotiating' | 'transferring' | 'completed' | 'cancelled' | 'closed';
|
|
634
640
|
/**
|
|
635
641
|
* PeerJS Peer constructor interface.
|
|
636
642
|
* Consumer must provide this constructor to P2P functions.
|
|
@@ -702,21 +708,6 @@ interface DataConnection {
|
|
|
702
708
|
/** Internal WebRTC data channel (for buffer monitoring). */
|
|
703
709
|
_dc?: RTCDataChannel;
|
|
704
710
|
}
|
|
705
|
-
/**
|
|
706
|
-
* Common server configuration for P2P connections.
|
|
707
|
-
*/
|
|
708
|
-
interface P2PServerConfig {
|
|
709
|
-
/** PeerJS server host. */
|
|
710
|
-
host?: string;
|
|
711
|
-
/** PeerJS server port. */
|
|
712
|
-
port?: number;
|
|
713
|
-
/** PeerJS server path (default: /peerjs). */
|
|
714
|
-
peerjsPath?: string;
|
|
715
|
-
/** Whether to use secure connection. */
|
|
716
|
-
secure?: boolean;
|
|
717
|
-
/** ICE servers for WebRTC. */
|
|
718
|
-
iceServers?: RTCIceServer[];
|
|
719
|
-
}
|
|
720
711
|
/** Status event for P2P operations. */
|
|
721
712
|
interface P2PStatusEvent {
|
|
722
713
|
phase: string;
|
|
@@ -734,6 +725,15 @@ interface P2PMetadataEvent {
|
|
|
734
725
|
total: number;
|
|
735
726
|
/** Call this to signal the sender to begin transfer (when autoReady is false). */
|
|
736
727
|
sendReady?: () => void;
|
|
728
|
+
/** v3: Total number of files in a multi-file transfer (undefined for single file). */
|
|
729
|
+
fileCount?: number;
|
|
730
|
+
/** v3: List of all files (names and sizes) in a multi-file transfer. */
|
|
731
|
+
files?: Array<{
|
|
732
|
+
name: string;
|
|
733
|
+
size: number;
|
|
734
|
+
}>;
|
|
735
|
+
/** v3: Total size across all files. */
|
|
736
|
+
totalSize?: number;
|
|
737
737
|
}
|
|
738
738
|
/** Completion event for P2P receive operations. */
|
|
739
739
|
interface P2PReceiveCompleteEvent {
|
|
@@ -747,20 +747,76 @@ interface P2PCancellationEvent {
|
|
|
747
747
|
/** Optional cancellation message. */
|
|
748
748
|
message?: string;
|
|
749
749
|
}
|
|
750
|
+
/** Connection health event for monitoring. */
|
|
751
|
+
interface P2PConnectionHealthEvent {
|
|
752
|
+
/** ICE connection state. */
|
|
753
|
+
iceConnectionState: 'connected' | 'disconnected' | 'failed' | 'checking' | 'new' | 'closed';
|
|
754
|
+
/** Estimated round-trip time in milliseconds. */
|
|
755
|
+
rtt?: number;
|
|
756
|
+
/** Bytes currently buffered waiting to send. */
|
|
757
|
+
bufferedAmount?: number;
|
|
758
|
+
/** Milliseconds since last activity. */
|
|
759
|
+
lastActivityMs: number;
|
|
760
|
+
}
|
|
761
|
+
/** Resumable transfer info. */
|
|
762
|
+
interface P2PResumeInfo {
|
|
763
|
+
/** Session ID to resume. */
|
|
764
|
+
sessionId: string;
|
|
765
|
+
/** Bytes already received in previous session. */
|
|
766
|
+
receivedBytes: number;
|
|
767
|
+
/** Total bytes expected. */
|
|
768
|
+
totalBytes: number;
|
|
769
|
+
/** Whether resume is possible. */
|
|
770
|
+
canResume: boolean;
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* Return value from startP2PSend containing session control.
|
|
774
|
+
*/
|
|
775
|
+
interface P2PSendSession {
|
|
776
|
+
/** The PeerJS peer instance. */
|
|
777
|
+
peer: PeerInstance;
|
|
778
|
+
/** The generated sharing code. */
|
|
779
|
+
code: string;
|
|
780
|
+
/** The unique session ID for this transfer. */
|
|
781
|
+
sessionId: string;
|
|
782
|
+
/** Stop the session and clean up resources. */
|
|
783
|
+
stop: () => void;
|
|
784
|
+
/** Get the current session state. */
|
|
785
|
+
getStatus: () => P2PSendState;
|
|
786
|
+
/** Get the number of bytes sent so far. */
|
|
787
|
+
getBytesSent: () => number;
|
|
788
|
+
/** Get the connected receiver's peer ID (if connected). */
|
|
789
|
+
getConnectedPeerId: () => string | null;
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* Return value from startP2PReceive containing session control.
|
|
793
|
+
*/
|
|
794
|
+
interface P2PReceiveSession {
|
|
795
|
+
/** The PeerJS peer instance. */
|
|
796
|
+
peer: PeerInstance;
|
|
797
|
+
/** Stop the session and clean up resources. */
|
|
798
|
+
stop: () => void;
|
|
799
|
+
/** Get the current session state. */
|
|
800
|
+
getStatus: () => P2PReceiveState;
|
|
801
|
+
/** Get the number of bytes received so far. */
|
|
802
|
+
getBytesReceived: () => number;
|
|
803
|
+
/** Get the expected total bytes (0 if metadata not received). */
|
|
804
|
+
getTotalBytes: () => number;
|
|
805
|
+
/** Get the current session ID (if received from sender). */
|
|
806
|
+
getSessionId: () => string | null;
|
|
807
|
+
}
|
|
750
808
|
/**
|
|
751
|
-
* Options for
|
|
809
|
+
* Options for DropgateClient.p2pSend().
|
|
810
|
+
* Server connection, serverInfo, peerjsPath, iceServers, and cryptoObj
|
|
811
|
+
* are all provided internally by the client.
|
|
752
812
|
*/
|
|
753
|
-
interface
|
|
754
|
-
/** File to send. */
|
|
755
|
-
file: FileSource;
|
|
813
|
+
interface P2PSendFileOptions {
|
|
814
|
+
/** File(s) to send. A single file or an array for multi-file transfers. */
|
|
815
|
+
file: FileSource | FileSource[];
|
|
756
816
|
/** PeerJS Peer constructor - REQUIRED. */
|
|
757
817
|
Peer: PeerConstructor;
|
|
758
|
-
/** Server info (optional, for capability checking). */
|
|
759
|
-
serverInfo?: ServerInfo;
|
|
760
818
|
/** Custom code generator function. */
|
|
761
819
|
codeGenerator?: (cryptoObj?: CryptoAdapter) => string;
|
|
762
|
-
/** Crypto object for secure code generation. */
|
|
763
|
-
cryptoObj?: CryptoAdapter;
|
|
764
820
|
/** Max attempts to register a peer ID. */
|
|
765
821
|
maxAttempts?: number;
|
|
766
822
|
/** Chunk size for data transfer. */
|
|
@@ -773,6 +829,12 @@ interface P2PSendOptions extends P2PServerConfig {
|
|
|
773
829
|
bufferLowWaterMark?: number;
|
|
774
830
|
/** Heartbeat interval in ms for long transfers (default: 5000, 0 to disable). */
|
|
775
831
|
heartbeatIntervalMs?: number;
|
|
832
|
+
/** Enable chunk-level acknowledgments for flow control (default: true). */
|
|
833
|
+
chunkAcknowledgments?: boolean;
|
|
834
|
+
/** Maximum unacknowledged chunks before pausing (default: 32). */
|
|
835
|
+
maxUnackedChunks?: number;
|
|
836
|
+
/** ICE restart timeout in ms (default: 10000). */
|
|
837
|
+
iceRestartTimeoutMs?: number;
|
|
776
838
|
/** Callback when code is generated. */
|
|
777
839
|
onCode?: (code: string, attempt: number) => void;
|
|
778
840
|
/** Callback for status updates. */
|
|
@@ -787,36 +849,21 @@ interface P2PSendOptions extends P2PServerConfig {
|
|
|
787
849
|
onDisconnect?: () => void;
|
|
788
850
|
/** Callback when transfer is cancelled by either party. */
|
|
789
851
|
onCancel?: (evt: P2PCancellationEvent) => void;
|
|
852
|
+
/** Connection health monitoring callback. */
|
|
853
|
+
onConnectionHealth?: (evt: P2PConnectionHealthEvent) => void;
|
|
854
|
+
/** Called when receiver requests resume from offset. */
|
|
855
|
+
onResumeRequest?: (info: P2PResumeInfo) => boolean;
|
|
790
856
|
}
|
|
791
857
|
/**
|
|
792
|
-
*
|
|
858
|
+
* Options for DropgateClient.p2pReceive().
|
|
859
|
+
* Server connection, serverInfo, peerjsPath, and iceServers
|
|
860
|
+
* are all provided internally by the client.
|
|
793
861
|
*/
|
|
794
|
-
interface
|
|
795
|
-
/** The PeerJS peer instance. */
|
|
796
|
-
peer: PeerInstance;
|
|
797
|
-
/** The generated sharing code. */
|
|
798
|
-
code: string;
|
|
799
|
-
/** The unique session ID for this transfer. */
|
|
800
|
-
sessionId: string;
|
|
801
|
-
/** Stop the session and clean up resources. */
|
|
802
|
-
stop: () => void;
|
|
803
|
-
/** Get the current session state. */
|
|
804
|
-
getStatus: () => P2PSendState;
|
|
805
|
-
/** Get the number of bytes sent so far. */
|
|
806
|
-
getBytesSent: () => number;
|
|
807
|
-
/** Get the connected receiver's peer ID (if connected). */
|
|
808
|
-
getConnectedPeerId: () => string | null;
|
|
809
|
-
}
|
|
810
|
-
/**
|
|
811
|
-
* Options for starting a P2P receive session.
|
|
812
|
-
*/
|
|
813
|
-
interface P2PReceiveOptions extends P2PServerConfig {
|
|
862
|
+
interface P2PReceiveFileOptions {
|
|
814
863
|
/** Sharing code to connect to. */
|
|
815
864
|
code: string;
|
|
816
865
|
/** PeerJS Peer constructor - REQUIRED. */
|
|
817
866
|
Peer: PeerConstructor;
|
|
818
|
-
/** Server info (optional, for capability checking). */
|
|
819
|
-
serverInfo?: ServerInfo;
|
|
820
867
|
/**
|
|
821
868
|
* Whether to automatically send the "ready" signal after receiving metadata.
|
|
822
869
|
* Default: true.
|
|
@@ -841,6 +888,17 @@ interface P2PReceiveOptions extends P2PServerConfig {
|
|
|
841
888
|
onData?: (chunk: Uint8Array) => Promise<void> | void;
|
|
842
889
|
/** Callback for progress updates. */
|
|
843
890
|
onProgress?: (evt: P2PReceiveProgressEvent) => void;
|
|
891
|
+
/** Callback when an individual file starts in a multi-file transfer. */
|
|
892
|
+
onFileStart?: (evt: {
|
|
893
|
+
fileIndex: number;
|
|
894
|
+
name: string;
|
|
895
|
+
size: number;
|
|
896
|
+
}) => void;
|
|
897
|
+
/** Callback when an individual file ends in a multi-file transfer. */
|
|
898
|
+
onFileEnd?: (evt: {
|
|
899
|
+
fileIndex: number;
|
|
900
|
+
receivedBytes: number;
|
|
901
|
+
}) => void;
|
|
844
902
|
/** Callback when transfer completes. */
|
|
845
903
|
onComplete?: (evt: P2PReceiveCompleteEvent) => void;
|
|
846
904
|
/** Callback on error. */
|
|
@@ -850,81 +908,191 @@ interface P2PReceiveOptions extends P2PServerConfig {
|
|
|
850
908
|
/** Callback when transfer is cancelled by either party. */
|
|
851
909
|
onCancel?: (evt: P2PCancellationEvent) => void;
|
|
852
910
|
}
|
|
911
|
+
|
|
853
912
|
/**
|
|
854
|
-
*
|
|
913
|
+
* Estimate total upload size including encryption overhead.
|
|
855
914
|
*/
|
|
856
|
-
|
|
857
|
-
/** The PeerJS peer instance. */
|
|
858
|
-
peer: PeerInstance;
|
|
859
|
-
/** Stop the session and clean up resources. */
|
|
860
|
-
stop: () => void;
|
|
861
|
-
/** Get the current session state. */
|
|
862
|
-
getStatus: () => P2PReceiveState;
|
|
863
|
-
/** Get the number of bytes received so far. */
|
|
864
|
-
getBytesReceived: () => number;
|
|
865
|
-
/** Get the expected total bytes (0 if metadata not received). */
|
|
866
|
-
getTotalBytes: () => number;
|
|
867
|
-
/** Get the current session ID (if received from sender). */
|
|
868
|
-
getSessionId: () => string | null;
|
|
869
|
-
}
|
|
870
|
-
|
|
915
|
+
declare function estimateTotalUploadSizeBytes(fileSizeBytes: number, totalChunks: number, isEncrypted: boolean): number;
|
|
871
916
|
/**
|
|
872
|
-
*
|
|
873
|
-
*
|
|
874
|
-
*
|
|
875
|
-
*
|
|
876
|
-
*
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
917
|
+
* Fetch server information from the /api/info endpoint.
|
|
918
|
+
* @param opts - Server target and request options.
|
|
919
|
+
* @returns The server base URL and server info object.
|
|
920
|
+
* @throws {DropgateNetworkError} If the server cannot be reached.
|
|
921
|
+
* @throws {DropgateProtocolError} If the server returns an invalid response.
|
|
922
|
+
*/
|
|
923
|
+
declare function getServerInfo(opts: GetServerInfoOptions): Promise<{
|
|
924
|
+
baseUrl: string;
|
|
925
|
+
serverInfo: ServerInfo;
|
|
926
|
+
}>;
|
|
927
|
+
/**
|
|
928
|
+
* Headless, environment-agnostic client for Dropgate file operations.
|
|
929
|
+
* Handles server communication, encryption, chunked uploads, downloads, and P2P transfers.
|
|
881
930
|
*
|
|
882
|
-
*
|
|
883
|
-
*
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
*/
|
|
893
|
-
|
|
931
|
+
* Server connection is configured once in the constructor — all methods use
|
|
932
|
+
* the stored server URL and cached server info automatically.
|
|
933
|
+
*/
|
|
934
|
+
declare class DropgateClient {
|
|
935
|
+
/** Client version string for compatibility checking. */
|
|
936
|
+
readonly clientVersion: string;
|
|
937
|
+
/** Chunk size in bytes for upload splitting. */
|
|
938
|
+
readonly chunkSize: number;
|
|
939
|
+
/** Fetch implementation used for HTTP requests. */
|
|
940
|
+
readonly fetchFn: FetchFn;
|
|
941
|
+
/** Crypto implementation for encryption operations. */
|
|
942
|
+
readonly cryptoObj: CryptoAdapter;
|
|
943
|
+
/** Base64 encoder/decoder for binary data. */
|
|
944
|
+
readonly base64: Base64Adapter;
|
|
945
|
+
/** Resolved base URL (e.g. 'https://dropgate.link'). May change during HTTP fallback. */
|
|
946
|
+
baseUrl: string;
|
|
947
|
+
/** Whether to automatically retry with HTTP when HTTPS fails. */
|
|
948
|
+
private _fallbackToHttp;
|
|
949
|
+
/** Cached compatibility result (null until first connect()). */
|
|
950
|
+
private _compat;
|
|
951
|
+
/** In-flight connect promise to deduplicate concurrent calls. */
|
|
952
|
+
private _connectPromise;
|
|
953
|
+
/**
|
|
954
|
+
* Create a new DropgateClient instance.
|
|
955
|
+
* @param opts - Client configuration options including server URL.
|
|
956
|
+
* @throws {DropgateValidationError} If clientVersion or server is missing or invalid.
|
|
957
|
+
*/
|
|
958
|
+
constructor(opts: DropgateClientOptions);
|
|
959
|
+
/**
|
|
960
|
+
* Get the server target (host, port, secure) derived from the current baseUrl.
|
|
961
|
+
* Useful for passing to standalone functions that still need a ServerTarget.
|
|
962
|
+
*/
|
|
963
|
+
get serverTarget(): ServerTarget;
|
|
964
|
+
/**
|
|
965
|
+
* Connect to the server: fetch server info and check version compatibility.
|
|
966
|
+
* Results are cached — subsequent calls return instantly without network requests.
|
|
967
|
+
* Concurrent calls are deduplicated.
|
|
968
|
+
*
|
|
969
|
+
* @param opts - Optional timeout and abort signal.
|
|
970
|
+
* @returns Compatibility result with server info.
|
|
971
|
+
* @throws {DropgateNetworkError} If the server cannot be reached.
|
|
972
|
+
* @throws {DropgateProtocolError} If the server returns an invalid response.
|
|
973
|
+
*/
|
|
974
|
+
connect(opts?: ConnectOptions): Promise<CompatibilityResult & {
|
|
975
|
+
serverInfo: ServerInfo;
|
|
976
|
+
baseUrl: string;
|
|
977
|
+
}>;
|
|
978
|
+
private _fetchAndCheckCompat;
|
|
979
|
+
/**
|
|
980
|
+
* Pure version compatibility check (no network calls).
|
|
981
|
+
*/
|
|
982
|
+
private _checkVersionCompat;
|
|
983
|
+
/**
|
|
984
|
+
* Resolve a user-entered sharing code or URL via the server.
|
|
985
|
+
* @param value - The sharing code or URL to resolve.
|
|
986
|
+
* @param opts - Optional timeout and abort signal.
|
|
987
|
+
* @returns The resolved share target information.
|
|
988
|
+
* @throws {DropgateProtocolError} If the share lookup fails.
|
|
989
|
+
*/
|
|
990
|
+
resolveShareTarget(value: string, opts?: ConnectOptions): Promise<ShareTargetResult>;
|
|
991
|
+
/**
|
|
992
|
+
* Fetch metadata for a single file from the server.
|
|
993
|
+
* @param fileId - The file ID to fetch metadata for.
|
|
994
|
+
* @param opts - Optional connection options (timeout, signal).
|
|
995
|
+
* @returns File metadata including size, filename, and encryption status.
|
|
996
|
+
* @throws {DropgateNetworkError} If the server cannot be reached.
|
|
997
|
+
* @throws {DropgateProtocolError} If the file is not found or server returns an error.
|
|
998
|
+
*/
|
|
999
|
+
getFileMetadata(fileId: string, opts?: ConnectOptions): Promise<FileMetadata>;
|
|
1000
|
+
/**
|
|
1001
|
+
* Fetch metadata for a bundle from the server and derive computed fields.
|
|
1002
|
+
* For sealed bundles, decrypts the manifest to extract file list.
|
|
1003
|
+
* Automatically derives totalSizeBytes and fileCount from the files array.
|
|
1004
|
+
* @param bundleId - The bundle ID to fetch metadata for.
|
|
1005
|
+
* @param keyB64 - Base64-encoded decryption key (required for encrypted bundles).
|
|
1006
|
+
* @param opts - Optional connection options (timeout, signal).
|
|
1007
|
+
* @returns Complete bundle metadata with all files and computed fields.
|
|
1008
|
+
* @throws {DropgateNetworkError} If the server cannot be reached.
|
|
1009
|
+
* @throws {DropgateProtocolError} If the bundle is not found or server returns an error.
|
|
1010
|
+
* @throws {DropgateValidationError} If decryption key is missing for encrypted bundle.
|
|
1011
|
+
*/
|
|
1012
|
+
getBundleMetadata(bundleId: string, keyB64?: string, opts?: ConnectOptions): Promise<BundleMetadata>;
|
|
1013
|
+
/**
|
|
1014
|
+
* Validate file and upload settings against server capabilities.
|
|
1015
|
+
* @param opts - Validation options containing file, settings, and server info.
|
|
1016
|
+
* @returns True if validation passes.
|
|
1017
|
+
* @throws {DropgateValidationError} If any validation check fails.
|
|
1018
|
+
*/
|
|
1019
|
+
validateUploadInputs(opts: ValidateUploadOptions): boolean;
|
|
1020
|
+
/**
|
|
1021
|
+
* Upload one or more files to the server with optional encryption.
|
|
1022
|
+
* Single files use the standard upload protocol.
|
|
1023
|
+
* Multiple files use the bundle protocol, grouping files under a single download link.
|
|
1024
|
+
*
|
|
1025
|
+
* @param opts - Upload options including file(s) and settings.
|
|
1026
|
+
* @returns Upload session with result promise and cancellation support.
|
|
1027
|
+
*/
|
|
1028
|
+
uploadFiles(opts: UploadFilesOptions): Promise<UploadSession>;
|
|
1029
|
+
/**
|
|
1030
|
+
* Upload a single file's chunks to the server. Used internally by uploadFiles().
|
|
1031
|
+
*/
|
|
1032
|
+
private _uploadFileChunks;
|
|
1033
|
+
/**
|
|
1034
|
+
* Download one or more files from the server with optional decryption.
|
|
1035
|
+
*
|
|
1036
|
+
* For single files, use `fileId`. For bundles, use `bundleId`.
|
|
1037
|
+
* With `asZip: true` on bundles, streams a ZIP archive via `onData`.
|
|
1038
|
+
* Without `asZip`, delivers files individually via `onFileStart`/`onFileData`/`onFileEnd`.
|
|
1039
|
+
*
|
|
1040
|
+
* @param opts - Download options including file/bundle ID and optional key.
|
|
1041
|
+
* @returns Download result containing filename(s) and received bytes.
|
|
1042
|
+
*/
|
|
1043
|
+
downloadFiles(opts: DownloadFilesOptions): Promise<DownloadResult>;
|
|
1044
|
+
/**
|
|
1045
|
+
* Download a single file, handling encryption/decryption internally.
|
|
1046
|
+
* Preserves the original downloadFile() behavior.
|
|
1047
|
+
*/
|
|
1048
|
+
private _downloadSingleFile;
|
|
1049
|
+
/**
|
|
1050
|
+
* Stream a single file's content into a callback, handling decryption if needed.
|
|
1051
|
+
* Returns total bytes received from the network (encrypted size).
|
|
1052
|
+
*/
|
|
1053
|
+
private _streamFileIntoCallback;
|
|
1054
|
+
/**
|
|
1055
|
+
* Start a P2P send session. Connects to the signalling server and waits for a receiver.
|
|
1056
|
+
*
|
|
1057
|
+
* Server info, peerjsPath, iceServers, and cryptoObj are provided automatically
|
|
1058
|
+
* from the client's cached server info and configuration.
|
|
1059
|
+
*
|
|
1060
|
+
* @param opts - P2P send options (file, Peer constructor, callbacks, tuning).
|
|
1061
|
+
* @returns P2P send session with control methods.
|
|
1062
|
+
* @throws {DropgateValidationError} If P2P is not enabled on the server.
|
|
1063
|
+
* @throws {DropgateNetworkError} If the signalling server cannot be reached.
|
|
1064
|
+
*/
|
|
1065
|
+
p2pSend(opts: P2PSendFileOptions): Promise<P2PSendSession>;
|
|
1066
|
+
/**
|
|
1067
|
+
* Start a P2P receive session. Connects to a sender via their sharing code.
|
|
1068
|
+
*
|
|
1069
|
+
* Server info, peerjsPath, and iceServers are provided automatically
|
|
1070
|
+
* from the client's cached server info.
|
|
1071
|
+
*
|
|
1072
|
+
* @param opts - P2P receive options (code, Peer constructor, callbacks, tuning).
|
|
1073
|
+
* @returns P2P receive session with control methods.
|
|
1074
|
+
* @throws {DropgateValidationError} If P2P is not enabled on the server.
|
|
1075
|
+
* @throws {DropgateNetworkError} If the signalling server cannot be reached.
|
|
1076
|
+
*/
|
|
1077
|
+
p2pReceive(opts: P2PReceiveFileOptions): Promise<P2PReceiveSession>;
|
|
1078
|
+
private _attemptChunkUpload;
|
|
1079
|
+
}
|
|
894
1080
|
|
|
895
1081
|
/**
|
|
896
|
-
*
|
|
897
|
-
*
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
*
|
|
902
|
-
*
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
*
|
|
907
|
-
*
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
* host: 'dropgate.link',
|
|
911
|
-
* secure: true,
|
|
912
|
-
* onMeta: ({ name, total }) => {
|
|
913
|
-
* // Consumer creates file writer
|
|
914
|
-
* writer = createWriteStream(name);
|
|
915
|
-
* },
|
|
916
|
-
* onData: async (chunk) => {
|
|
917
|
-
* // Consumer writes data
|
|
918
|
-
* await writer.write(chunk);
|
|
919
|
-
* },
|
|
920
|
-
* onComplete: () => {
|
|
921
|
-
* writer.close();
|
|
922
|
-
* console.log('Done!');
|
|
923
|
-
* },
|
|
924
|
-
* });
|
|
925
|
-
* ```
|
|
926
|
-
*/
|
|
927
|
-
declare function startP2PReceive(opts: P2PReceiveOptions): Promise<P2PReceiveSession>;
|
|
1082
|
+
* Get the default Base64 adapter for the current environment.
|
|
1083
|
+
* Automatically detects Node.js Buffer vs browser btoa/atob.
|
|
1084
|
+
*/
|
|
1085
|
+
declare function getDefaultBase64(): Base64Adapter;
|
|
1086
|
+
/**
|
|
1087
|
+
* Get the default crypto object for the current environment.
|
|
1088
|
+
* Returns globalThis.crypto if available.
|
|
1089
|
+
*/
|
|
1090
|
+
declare function getDefaultCrypto(): CryptoAdapter | undefined;
|
|
1091
|
+
/**
|
|
1092
|
+
* Get the default fetch function for the current environment.
|
|
1093
|
+
* Returns globalThis.fetch if available.
|
|
1094
|
+
*/
|
|
1095
|
+
declare function getDefaultFetch(): FetchFn | undefined;
|
|
928
1096
|
|
|
929
1097
|
/**
|
|
930
1098
|
* Check if a hostname is localhost
|
|
@@ -944,31 +1112,4 @@ declare function generateP2PCode(cryptoObj?: CryptoAdapter): string;
|
|
|
944
1112
|
*/
|
|
945
1113
|
declare function isP2PCodeLike(code: string): boolean;
|
|
946
1114
|
|
|
947
|
-
|
|
948
|
-
* Resolve P2P server configuration from user options and server capabilities.
|
|
949
|
-
* User-provided values take precedence over server capabilities.
|
|
950
|
-
*/
|
|
951
|
-
declare function resolvePeerConfig(userConfig: P2PServerConfig, serverCaps?: P2PCapabilities): {
|
|
952
|
-
path: string;
|
|
953
|
-
iceServers: RTCIceServer[];
|
|
954
|
-
};
|
|
955
|
-
/**
|
|
956
|
-
* Build PeerJS connection options from P2P server configuration.
|
|
957
|
-
*/
|
|
958
|
-
declare function buildPeerOptions(config?: P2PServerConfig): PeerOptions;
|
|
959
|
-
interface CreatePeerWithRetriesOptions {
|
|
960
|
-
code?: string | null;
|
|
961
|
-
codeGenerator: () => string;
|
|
962
|
-
maxAttempts: number;
|
|
963
|
-
buildPeer: (id: string) => PeerInstance;
|
|
964
|
-
onCode?: (code: string, attempt: number) => void;
|
|
965
|
-
}
|
|
966
|
-
/**
|
|
967
|
-
* Create a peer with retries if the code is already taken
|
|
968
|
-
*/
|
|
969
|
-
declare function createPeerWithRetries(opts: CreatePeerWithRetriesOptions): Promise<{
|
|
970
|
-
peer: PeerInstance;
|
|
971
|
-
code: string;
|
|
972
|
-
}>;
|
|
973
|
-
|
|
974
|
-
export { AES_GCM_IV_BYTES, AES_GCM_TAG_BYTES, type AbortSignalWithCleanup, type Base64Adapter, type BaseProgressEvent, type CompatibilityResult, type CryptoAdapter, DEFAULT_CHUNK_SIZE, type DataConnection, type DataConnectionEvents, type DownloadOptions, type DownloadProgressEvent, type DownloadResult, DropgateAbortError, DropgateClient, type DropgateClientOptions, DropgateError, type DropgateErrorOptions, DropgateNetworkError, DropgateProtocolError, DropgateTimeoutError, DropgateValidationError, ENCRYPTION_OVERHEAD_PER_CHUNK, type FetchFn, type FetchJsonOptions, type FetchJsonResult, type FileMetadata, type FileSource, type GetServerInfoOptions, type LoggerFn, type P2PCapabilities, type P2PMetadataEvent, type P2PReceiveCompleteEvent, type P2PReceiveOptions, type P2PReceiveProgressEvent, type P2PReceiveSession, type P2PSendOptions, type P2PSendProgressEvent, type P2PSendSession, type P2PServerConfig, type P2PStatusEvent, type PeerConstructor, type PeerInstance, type PeerInstanceEvents, type PeerOptions, type SemverParts, type ServerCapabilities, type ServerInfo, type ServerTarget, type ShareTargetResult, type UploadCapabilities, type UploadOptions, type UploadProgressEvent, type UploadResult, type ValidateUploadOptions, type WebUICapabilities, arrayBufferToBase64, base64ToBytes, buildBaseUrl, buildPeerOptions, bytesToBase64, createPeerWithRetries, decryptChunk, decryptFilenameFromBase64, encryptFilenameToBase64, encryptToBlob, estimateTotalUploadSizeBytes, exportKeyBase64, fetchJson, generateAesGcmKey, generateP2PCode, getDefaultBase64, getDefaultCrypto, getDefaultFetch, getServerInfo, importKeyFromBase64, isLocalhostHostname, isP2PCodeLike, isSecureContextForP2P, lifetimeToMs, makeAbortSignal, parseSemverMajorMinor, parseServerUrl, resolvePeerConfig, sha256Hex, sleep, startP2PReceive, startP2PSend, validatePlainFilename };
|
|
1115
|
+
export { AES_GCM_IV_BYTES, AES_GCM_TAG_BYTES, type AbortSignalWithCleanup, type Base64Adapter, type BaseProgressEvent, type BundleMetadata, type CompatibilityResult, type ConnectOptions, type CryptoAdapter, DEFAULT_CHUNK_SIZE, type DataConnection, type DataConnectionEvents, type DownloadFilesOptions, type DownloadProgressEvent, type DownloadResult, DropgateAbortError, DropgateClient, type DropgateClientOptions, DropgateError, type DropgateErrorOptions, DropgateNetworkError, DropgateProtocolError, DropgateTimeoutError, DropgateValidationError, ENCRYPTION_OVERHEAD_PER_CHUNK, type FetchFn, type FetchJsonOptions, type FetchJsonResult, type FileMetadata, type FileSource, type GetServerInfoOptions, type P2PCancellationEvent, type P2PCapabilities, type P2PConnectionHealthEvent, type P2PMetadataEvent, type P2PReceiveCompleteEvent, type P2PReceiveFileOptions, type P2PReceiveProgressEvent, type P2PReceiveSession, type P2PReceiveState, type P2PResumeInfo, type P2PSendFileOptions, type P2PSendProgressEvent, type P2PSendSession, type P2PSendState, type P2PStatusEvent, type PeerConstructor, type PeerInstance, type PeerInstanceEvents, type PeerOptions, type SemverParts, type ServerCapabilities, type ServerInfo, type ServerTarget, type ShareTargetResult, StreamingZipWriter, type UploadCapabilities, type UploadFilesOptions, type UploadProgressEvent, type UploadResult, type UploadSession, type ValidateUploadOptions, type WebUICapabilities, arrayBufferToBase64, base64ToBytes, buildBaseUrl, bytesToBase64, decryptChunk, decryptFilenameFromBase64, encryptFilenameToBase64, encryptToBlob, estimateTotalUploadSizeBytes, exportKeyBase64, fetchJson, generateAesGcmKey, generateP2PCode, getDefaultBase64, getDefaultCrypto, getDefaultFetch, getServerInfo, importKeyFromBase64, isLocalhostHostname, isP2PCodeLike, isSecureContextForP2P, lifetimeToMs, makeAbortSignal, parseSemverMajorMinor, parseServerUrl, sha256Hex, sleep, validatePlainFilename };
|