@kesha-antonov/react-native-background-downloader 4.7.0 → 4.8.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 +75 -32
- package/android/src/main/java/com/eko/DownloadConstants.kt +5 -0
- package/android/src/main/java/com/eko/Downloader.kt +12 -5
- package/android/src/main/java/com/eko/RNBGDUploadTaskConfig.kt +36 -1
- package/android/src/main/java/com/eko/RNBackgroundDownloaderModuleImpl.kt +94 -54
- package/android/src/main/java/com/eko/ResumableDownloader.kt +34 -13
- package/android/src/main/java/com/eko/UnmeteredNetworkGate.kt +134 -17
- package/android/src/main/java/com/eko/UploadEventEmitter.kt +26 -1
- package/android/src/main/java/com/eko/Uploader.kt +187 -17
- package/android/src/main/java/com/eko/handlers/OnProgress.kt +1 -1
- package/android/src/main/java/com/eko/utils/HeaderUtils.kt +9 -0
- package/android/src/main/java/com/eko/utils/RedirectResolver.kt +29 -1
- package/android/src/test/java/com/eko/DownloadCompleteReceiverTest.kt +57 -0
- package/android/src/test/java/com/eko/ResumableDownloaderRedirectTest.kt +77 -0
- package/android/src/test/java/com/eko/UnmeteredNetworkGateTest.kt +248 -0
- package/android/src/test/java/com/eko/UploadPartRangesTest.kt +33 -0
- package/android/src/test/java/com/eko/UploaderMultipartTest.kt +10 -1
- package/android/src/test/java/com/eko/UploaderPartsTest.kt +222 -0
- package/android/src/test/java/com/eko/UploaderResponseTest.kt +26 -0
- package/android/src/test/java/com/eko/utils/RedirectResolverTest.kt +66 -0
- package/ios/RNBGDUploadTaskConfig.h +26 -0
- package/ios/RNBGDUploadTaskConfig.mm +69 -3
- package/ios/RNBackgroundDownloader.mm +563 -43
- package/lib/NativeRNBackgroundDownloader.d.ts +15 -0
- package/lib/UploadTask.d.ts +5 -1
- package/lib/UploadTask.js +22 -4
- package/lib/index.js +57 -27
- package/lib/types.d.ts +33 -2
- package/package.json +1 -1
- package/src/NativeRNBackgroundDownloader.ts +23 -0
- package/src/UploadTask.ts +23 -1
- package/src/index.ts +60 -27
- package/src/types.ts +42 -2
package/src/types.ts
CHANGED
|
@@ -238,9 +238,24 @@ export type UploadProgressHandlerParams = {
|
|
|
238
238
|
|
|
239
239
|
export type UploadProgressHandler = (params: UploadProgressHandlerParams) => void
|
|
240
240
|
|
|
241
|
+
export type UploadPartResult = {
|
|
242
|
+
// 1-based, matching the position in partUrls and S3's part numbers
|
|
243
|
+
partNumber: number
|
|
244
|
+
responseCode: number
|
|
245
|
+
responseBody: string
|
|
246
|
+
// Lowercased header names, e.g. responseHeaders.etag
|
|
247
|
+
responseHeaders: Record<string, string>
|
|
248
|
+
bytes: number
|
|
249
|
+
}
|
|
250
|
+
|
|
241
251
|
export type UploadDoneHandlerParams = {
|
|
252
|
+
// For an upload with partUrls: the last part's response
|
|
242
253
|
responseCode: number
|
|
243
254
|
responseBody: string
|
|
255
|
+
// Lowercased header names, e.g. responseHeaders.etag
|
|
256
|
+
responseHeaders: Record<string, string>
|
|
257
|
+
// Set for an upload with partUrls, in part order
|
|
258
|
+
parts?: UploadPartResult[]
|
|
244
259
|
bytesUploaded: number
|
|
245
260
|
bytesTotal: number
|
|
246
261
|
}
|
|
@@ -270,6 +285,10 @@ export interface UploadTaskInfoNative {
|
|
|
270
285
|
bytesTotal: number
|
|
271
286
|
errorCode: number
|
|
272
287
|
state: number
|
|
288
|
+
responseCode?: number | null
|
|
289
|
+
responseBody?: string | null
|
|
290
|
+
responseHeaders?: Record<string, string> | null
|
|
291
|
+
parts?: UploadPartResult[] | null
|
|
273
292
|
}
|
|
274
293
|
|
|
275
294
|
export interface UploadTaskInfo {
|
|
@@ -278,13 +297,27 @@ export interface UploadTaskInfo {
|
|
|
278
297
|
}
|
|
279
298
|
|
|
280
299
|
export type UploadParams = {
|
|
281
|
-
|
|
300
|
+
// Not needed with partUrls
|
|
301
|
+
url?: string
|
|
282
302
|
source: string
|
|
303
|
+
// Defaults to POST, or PUT with partUrls
|
|
283
304
|
method?: 'POST' | 'PUT' | 'PATCH'
|
|
284
305
|
headers?: Headers
|
|
285
306
|
fieldName?: string
|
|
286
307
|
mimeType?: string
|
|
287
308
|
parameters?: Record<string, string>
|
|
309
|
+
/**
|
|
310
|
+
* Upload `source` in parts, one URL per part (e.g. S3 multipart upload with a
|
|
311
|
+
* presigned UploadPart URL each). Part `i` is sent as the raw body to `partUrls[i]`;
|
|
312
|
+
* can't be combined with `fieldName` or `parameters`.
|
|
313
|
+
*/
|
|
314
|
+
partUrls?: string[]
|
|
315
|
+
/**
|
|
316
|
+
* Bytes per part, the last part taking what's left. Defaults to
|
|
317
|
+
* `Math.ceil(fileSize / partUrls.length)`. The upload fails if the parts don't
|
|
318
|
+
* cover the file exactly.
|
|
319
|
+
*/
|
|
320
|
+
partSize?: number
|
|
288
321
|
isAllowedOverRoaming?: boolean
|
|
289
322
|
isAllowedOverMetered?: boolean
|
|
290
323
|
}
|
|
@@ -297,6 +330,11 @@ export interface UploadTask {
|
|
|
297
330
|
bytesUploaded: number
|
|
298
331
|
bytesTotal: number
|
|
299
332
|
uploadParams?: UploadParams
|
|
333
|
+
// Set once the upload is done (also on a finished task from getExistingUploadTasks)
|
|
334
|
+
responseCode?: number
|
|
335
|
+
responseBody?: string
|
|
336
|
+
responseHeaders?: Record<string, string>
|
|
337
|
+
parts?: UploadPartResult[]
|
|
300
338
|
|
|
301
339
|
begin: (handler: UploadBeginHandler) => UploadTask
|
|
302
340
|
progress: (handler: UploadProgressHandler) => UploadTask
|
|
@@ -321,7 +359,7 @@ export type getExistingUploadTasks = () => Promise<UploadTask[]>
|
|
|
321
359
|
|
|
322
360
|
export interface UploadOption {
|
|
323
361
|
id: string
|
|
324
|
-
url
|
|
362
|
+
url?: string
|
|
325
363
|
source: string
|
|
326
364
|
method?: 'POST' | 'PUT' | 'PATCH'
|
|
327
365
|
headers?: Headers | undefined
|
|
@@ -329,6 +367,8 @@ export interface UploadOption {
|
|
|
329
367
|
fieldName?: string
|
|
330
368
|
mimeType?: string
|
|
331
369
|
parameters?: Record<string, string>
|
|
370
|
+
partUrls?: string[]
|
|
371
|
+
partSize?: number
|
|
332
372
|
isAllowedOverRoaming?: boolean
|
|
333
373
|
isAllowedOverMetered?: boolean
|
|
334
374
|
}
|