diff --git a/src/Transloadit.ts b/src/Transloadit.ts index efd6a91..b686188 100644 --- a/src/Transloadit.ts +++ b/src/Transloadit.ts @@ -159,7 +159,6 @@ export class Transloadit { const { params = {}, waitForCompletion = false, - isResumable = true, chunkSize: requestedChunkSize = Infinity, uploadConcurrency = 10, timeout = 24 * 60 * 60 * 1000, // 1 day @@ -170,13 +169,6 @@ export class Transloadit { assemblyId, } = opts - if (!isResumable) { - process.emitWarning( - 'Parameter value isResumable = false is deprecated. All uploads will be resumable (using TUS) in the future', - 'DeprecationWarning' - ) - } - // Keep track of how long the request took const startTimeMs = getHrTimeMs() @@ -242,25 +234,15 @@ export class Transloadit { method: 'post', timeout, params, - } - - if (isResumable) { - requestOpts.fields = { + fields: { tus_num_expected_upload_files: allStreams.length, - } + }, } - // upload as form multipart or tus? - const formUploadStreamsMap: Record = isResumable ? {} : allStreamsMap - - const result = await this._remoteJson( - requestOpts, - formUploadStreamsMap, - onUploadProgress - ) + const result = await this._remoteJson(requestOpts) checkResult(result) - if (isResumable && Object.keys(allStreamsMap).length > 0) { + if (Object.keys(allStreamsMap).length > 0) { await sendTusRequest({ streamsMap: allStreamsMap, assembly: result, @@ -678,7 +660,6 @@ export class Transloadit { private _appendForm( form: FormData, params: KeyVal, - streamsMap?: Record, fields?: Record ): void { const sigData = this.calcSignature(params) @@ -694,13 +675,6 @@ export class Transloadit { } form.append('signature', signature) - - if (streamsMap) { - Object.entries(streamsMap).forEach(([label, { stream, path }]) => { - const options = path ? undefined : { filename: label } // https://github.com/transloadit/node-sdk/issues/86 - form.append(label, stream, options) - }) - } } // Implements HTTP GET query params, handling the case where the url already @@ -743,11 +717,7 @@ export class Transloadit { // Responsible for making API calls. Automatically sends streams with any POST, // PUT or DELETE requests. Automatically adds signature parameters to all // requests. Also automatically parses the JSON response. - private async _remoteJson( - opts: RequestOptions, - streamsMap?: Record, - onProgress: CreateAssemblyOptions['onUploadProgress'] = () => {} - ): Promise { + private async _remoteJson(opts: RequestOptions): Promise { const { urlSuffix, url: urlInput, @@ -775,11 +745,9 @@ export class Transloadit { if (method === 'post' || method === 'put' || method === 'delete') { form = new FormData() - this._appendForm(form, params, streamsMap, fields) + this._appendForm(form, params, fields) } - const isUploadingStreams = streamsMap && Object.keys(streamsMap).length > 0 - const requestOpts: OptionsOfJSONResponseBody = { retry: this._gotRetry, body: form as FormData, @@ -792,18 +760,8 @@ export class Transloadit { responseType: 'json', } - // For non-file streams transfer encoding does not get set, and the uploaded files will not get accepted - // https://github.com/transloadit/node-sdk/issues/86 - // https://github.com/form-data/form-data/issues/394#issuecomment-573595015 - if (isUploadingStreams) requestOpts.headers!['transfer-encoding'] = 'chunked' - try { const request = got[method](url, requestOpts) - if (isUploadingStreams) { - request.on('uploadProgress', ({ transferred, total }) => - onProgress({ uploadedBytes: transferred, totalBytes: total }) - ) - } const { body } = await request return body } catch (err) { @@ -852,7 +810,6 @@ export interface CreateAssemblyOptions { [name: string]: Readable | intoStream.Input } waitForCompletion?: boolean - isResumable?: boolean chunkSize?: number uploadConcurrency?: number timeout?: number diff --git a/test/integration/live-api.test.ts b/test/integration/live-api.test.ts index 0b87779..4aa95b7 100644 --- a/test/integration/live-api.test.ts +++ b/test/integration/live-api.test.ts @@ -337,22 +337,19 @@ describe('API integration', { timeout: 60000 }, () => { expect(result.assembly_id).toMatch(promise.assemblyId) }) - async function testUploadProgress(isResumable: boolean) { + async function testUploadProgress() { const client = createClient() let progressCalled = false function onUploadProgress({ uploadedBytes, totalBytes }: UploadProgress) { // console.log(uploadedBytes) expect(uploadedBytes).toBeDefined() - if (isResumable) { - expect(totalBytes).toBeDefined() - expect(totalBytes).toBeGreaterThan(0) - } + expect(totalBytes).toBeDefined() + expect(totalBytes).toBeGreaterThan(0) progressCalled = true } const params: CreateAssemblyOptions = { - isResumable, params: { steps: { resize: resizeOriginalStep, @@ -368,12 +365,8 @@ describe('API integration', { timeout: 60000 }, () => { expect(progressCalled).toBe(true) } - it('should trigger progress callbacks when uploading files, resumable', async () => { - await testUploadProgress(true) - }) - - it('should trigger progress callbacks when uploading files, nonresumable', async () => { - await testUploadProgress(false) + it('should trigger progress callbacks when uploading files', async () => { + await testUploadProgress() }) it('should return properly waitForCompletion is false', async () => { diff --git a/test/unit/test-transloadit-client.test.ts b/test/unit/test-transloadit-client.test.ts index 591f783..352b683 100644 --- a/test/unit/test-transloadit-client.test.ts +++ b/test/unit/test-transloadit-client.test.ts @@ -151,14 +151,6 @@ describe('Transloadit', () => { it('should append all required fields to the request form', () => { const client = new Transloadit({ authKey: 'foo_key', authSecret: 'foo_secret' }) - const stream1 = new Readable() - const stream2 = new Readable() - - const streamsMap = { - stream1: { stream: stream1 }, - stream2: { stream: stream2 }, - } - const form = new FormData() const params = {} const fields = { @@ -170,7 +162,7 @@ describe('Transloadit', () => { const formAppendSpy = vi.spyOn(form, 'append') // @ts-expect-error This tests private internals - client._appendForm(form, params, streamsMap, fields) + client._appendForm(form, params, fields) expect(calcSignatureSpy).toHaveBeenCalledWith(params) @@ -181,8 +173,6 @@ describe('Transloadit', () => { 'signature', 'sha384:f146533532844d4f4e34221288be08e14a2779eeb802a35afa6a193762f58da95d2423a825aa4cb4c7420e25f75a5c90', ], - ['stream1', stream1, { filename: 'stream1' }], - ['stream2', stream2, { filename: 'stream2' }], ]) }) }) @@ -280,11 +270,7 @@ describe('Transloadit', () => { await client.createAssembly() - expect(spy).toBeCalledWith( - expect.objectContaining({ timeout: 24 * 60 * 60 * 1000 }), - {}, - expect.any(Function) - ) + expect(spy).toBeCalledWith(expect.objectContaining({ timeout: 24 * 60 * 60 * 1000 })) }) describe('_calcSignature', () => {