diff --git a/lib/index.d.ts b/lib/index.d.ts index 3ef96c9f..4a94eea2 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -32,7 +32,7 @@ interface UploadOptions { onProgress?: ((bytesSent: number, bytesTotal: number) => void) | null onChunkComplete?: ((chunkSize: number, bytesAccepted: number, bytesTotal: number) => void) | null - onSuccess?: (() => void) | null + onSuccess?: ((payload: OnSuccessPayload) => void) | null onError?: ((error: Error | DetailedError) => void) | null onShouldRetry?: | ((error: DetailedError, retryAttempt: number, options: UploadOptions) => boolean) @@ -59,6 +59,10 @@ interface UploadOptions { httpStack?: HttpStack } +interface OnSuccessPayload { + lastResponse: HttpResponse +} + interface UrlStorage { findAllUploads(): Promise findUploadsByFingerprint(fingerprint: string): Promise diff --git a/lib/index.test-d.ts b/lib/index.test-d.ts index 6f1f399d..0869f411 100644 --- a/lib/index.test-d.ts +++ b/lib/index.test-d.ts @@ -27,8 +27,9 @@ const upload = new tus.Upload(file, { console.log(bytesSent, bytesTotal, `${percentage}%`) }, onChunkComplete: (_chunkSize: number, _bytesAccepted: number) => {}, - onSuccess: () => { + onSuccess: (payload: tus.OnSuccessPayload) => { console.log('Download from %s complete', upload.url) + console.log('Response header', payload.lastResponse.getHeader('X-Info')) }, onError: (error: Error | DetailedError) => { console.error(`Failed because: ${error}`)