Skip to content

Commit 3f1acb0

Browse files
authored
remove isResumable option (#209)
* remove isResumable option was deprecated * fix outdated internal unit tests * fix fomatting
1 parent c1f24bd commit 3f1acb0

File tree

3 files changed

+13
-77
lines changed

3 files changed

+13
-77
lines changed

src/Transloadit.ts

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ export class Transloadit {
159159
const {
160160
params = {},
161161
waitForCompletion = false,
162-
isResumable = true,
163162
chunkSize: requestedChunkSize = Infinity,
164163
uploadConcurrency = 10,
165164
timeout = 24 * 60 * 60 * 1000, // 1 day
@@ -170,13 +169,6 @@ export class Transloadit {
170169
assemblyId,
171170
} = opts
172171

173-
if (!isResumable) {
174-
process.emitWarning(
175-
'Parameter value isResumable = false is deprecated. All uploads will be resumable (using TUS) in the future',
176-
'DeprecationWarning'
177-
)
178-
}
179-
180172
// Keep track of how long the request took
181173
const startTimeMs = getHrTimeMs()
182174

@@ -242,25 +234,15 @@ export class Transloadit {
242234
method: 'post',
243235
timeout,
244236
params,
245-
}
246-
247-
if (isResumable) {
248-
requestOpts.fields = {
237+
fields: {
249238
tus_num_expected_upload_files: allStreams.length,
250-
}
239+
},
251240
}
252241

253-
// upload as form multipart or tus?
254-
const formUploadStreamsMap: Record<string, Stream> = isResumable ? {} : allStreamsMap
255-
256-
const result = await this._remoteJson<Assembly>(
257-
requestOpts,
258-
formUploadStreamsMap,
259-
onUploadProgress
260-
)
242+
const result = await this._remoteJson<Assembly>(requestOpts)
261243
checkResult(result)
262244

263-
if (isResumable && Object.keys(allStreamsMap).length > 0) {
245+
if (Object.keys(allStreamsMap).length > 0) {
264246
await sendTusRequest({
265247
streamsMap: allStreamsMap,
266248
assembly: result,
@@ -678,7 +660,6 @@ export class Transloadit {
678660
private _appendForm(
679661
form: FormData,
680662
params: KeyVal,
681-
streamsMap?: Record<string, Stream>,
682663
fields?: Record<string, string | number>
683664
): void {
684665
const sigData = this.calcSignature(params)
@@ -694,13 +675,6 @@ export class Transloadit {
694675
}
695676

696677
form.append('signature', signature)
697-
698-
if (streamsMap) {
699-
Object.entries(streamsMap).forEach(([label, { stream, path }]) => {
700-
const options = path ? undefined : { filename: label } // https://github.com/transloadit/node-sdk/issues/86
701-
form.append(label, stream, options)
702-
})
703-
}
704678
}
705679

706680
// Implements HTTP GET query params, handling the case where the url already
@@ -743,11 +717,7 @@ export class Transloadit {
743717
// Responsible for making API calls. Automatically sends streams with any POST,
744718
// PUT or DELETE requests. Automatically adds signature parameters to all
745719
// requests. Also automatically parses the JSON response.
746-
private async _remoteJson<T>(
747-
opts: RequestOptions,
748-
streamsMap?: Record<string, Stream>,
749-
onProgress: CreateAssemblyOptions['onUploadProgress'] = () => {}
750-
): Promise<T> {
720+
private async _remoteJson<T>(opts: RequestOptions): Promise<T> {
751721
const {
752722
urlSuffix,
753723
url: urlInput,
@@ -775,11 +745,9 @@ export class Transloadit {
775745

776746
if (method === 'post' || method === 'put' || method === 'delete') {
777747
form = new FormData()
778-
this._appendForm(form, params, streamsMap, fields)
748+
this._appendForm(form, params, fields)
779749
}
780750

781-
const isUploadingStreams = streamsMap && Object.keys(streamsMap).length > 0
782-
783751
const requestOpts: OptionsOfJSONResponseBody = {
784752
retry: this._gotRetry,
785753
body: form as FormData,
@@ -792,18 +760,8 @@ export class Transloadit {
792760
responseType: 'json',
793761
}
794762

795-
// For non-file streams transfer encoding does not get set, and the uploaded files will not get accepted
796-
// https://github.com/transloadit/node-sdk/issues/86
797-
// https://github.com/form-data/form-data/issues/394#issuecomment-573595015
798-
if (isUploadingStreams) requestOpts.headers!['transfer-encoding'] = 'chunked'
799-
800763
try {
801764
const request = got[method]<T>(url, requestOpts)
802-
if (isUploadingStreams) {
803-
request.on('uploadProgress', ({ transferred, total }) =>
804-
onProgress({ uploadedBytes: transferred, totalBytes: total })
805-
)
806-
}
807765
const { body } = await request
808766
return body
809767
} catch (err) {
@@ -852,7 +810,6 @@ export interface CreateAssemblyOptions {
852810
[name: string]: Readable | intoStream.Input
853811
}
854812
waitForCompletion?: boolean
855-
isResumable?: boolean
856813
chunkSize?: number
857814
uploadConcurrency?: number
858815
timeout?: number

test/integration/live-api.test.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -337,22 +337,19 @@ describe('API integration', { timeout: 60000 }, () => {
337337
expect(result.assembly_id).toMatch(promise.assemblyId)
338338
})
339339

340-
async function testUploadProgress(isResumable: boolean) {
340+
async function testUploadProgress() {
341341
const client = createClient()
342342

343343
let progressCalled = false
344344
function onUploadProgress({ uploadedBytes, totalBytes }: UploadProgress) {
345345
// console.log(uploadedBytes)
346346
expect(uploadedBytes).toBeDefined()
347-
if (isResumable) {
348-
expect(totalBytes).toBeDefined()
349-
expect(totalBytes).toBeGreaterThan(0)
350-
}
347+
expect(totalBytes).toBeDefined()
348+
expect(totalBytes).toBeGreaterThan(0)
351349
progressCalled = true
352350
}
353351

354352
const params: CreateAssemblyOptions = {
355-
isResumable,
356353
params: {
357354
steps: {
358355
resize: resizeOriginalStep,
@@ -368,12 +365,8 @@ describe('API integration', { timeout: 60000 }, () => {
368365
expect(progressCalled).toBe(true)
369366
}
370367

371-
it('should trigger progress callbacks when uploading files, resumable', async () => {
372-
await testUploadProgress(true)
373-
})
374-
375-
it('should trigger progress callbacks when uploading files, nonresumable', async () => {
376-
await testUploadProgress(false)
368+
it('should trigger progress callbacks when uploading files', async () => {
369+
await testUploadProgress()
377370
})
378371

379372
it('should return properly waitForCompletion is false', async () => {

test/unit/test-transloadit-client.test.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,6 @@ describe('Transloadit', () => {
151151
it('should append all required fields to the request form', () => {
152152
const client = new Transloadit({ authKey: 'foo_key', authSecret: 'foo_secret' })
153153

154-
const stream1 = new Readable()
155-
const stream2 = new Readable()
156-
157-
const streamsMap = {
158-
stream1: { stream: stream1 },
159-
stream2: { stream: stream2 },
160-
}
161-
162154
const form = new FormData()
163155
const params = {}
164156
const fields = {
@@ -170,7 +162,7 @@ describe('Transloadit', () => {
170162
const formAppendSpy = vi.spyOn(form, 'append')
171163

172164
// @ts-expect-error This tests private internals
173-
client._appendForm(form, params, streamsMap, fields)
165+
client._appendForm(form, params, fields)
174166

175167
expect(calcSignatureSpy).toHaveBeenCalledWith(params)
176168

@@ -181,8 +173,6 @@ describe('Transloadit', () => {
181173
'signature',
182174
'sha384:f146533532844d4f4e34221288be08e14a2779eeb802a35afa6a193762f58da95d2423a825aa4cb4c7420e25f75a5c90',
183175
],
184-
['stream1', stream1, { filename: 'stream1' }],
185-
['stream2', stream2, { filename: 'stream2' }],
186176
])
187177
})
188178
})
@@ -280,11 +270,7 @@ describe('Transloadit', () => {
280270

281271
await client.createAssembly()
282272

283-
expect(spy).toBeCalledWith(
284-
expect.objectContaining({ timeout: 24 * 60 * 60 * 1000 }),
285-
{},
286-
expect.any(Function)
287-
)
273+
expect(spy).toBeCalledWith(expect.objectContaining({ timeout: 24 * 60 * 60 * 1000 }))
288274
})
289275

290276
describe('_calcSignature', () => {

0 commit comments

Comments
 (0)