@kesha-antonov/react-native-background-downloader 4.5.6 → 4.5.9
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 +5 -1
- package/android/src/main/java/com/eko/DownloadConstants.kt +7 -0
- package/android/src/main/java/com/eko/Downloader.kt +80 -111
- package/android/src/main/java/com/eko/PromiseExtensions.kt +36 -0
- package/android/src/main/java/com/eko/RNBGDTaskConfig.kt +4 -1
- package/android/src/main/java/com/eko/RNBackgroundDownloaderModuleImpl.kt +102 -144
- package/android/src/main/java/com/eko/ResumableDownloadService.kt +153 -37
- package/android/src/main/java/com/eko/ResumableDownloader.kt +66 -12
- package/android/src/main/java/com/eko/UIDTDownloadJobService.kt +25 -4
- package/android/src/main/java/com/eko/UnmeteredNetworkGate.kt +366 -0
- package/android/src/main/java/com/eko/uidt/UIDTJobManager.kt +76 -14
- package/android/src/main/java/com/eko/uidt/UIDTJobState.kt +11 -0
- package/android/src/main/java/com/eko/utils/NetworkRequestUtils.kt +43 -0
- package/android/src/main/java/com/eko/utils/ReadableConverters.kt +55 -0
- package/android/src/main/java/com/eko/utils/RedirectResolver.kt +97 -0
- package/android/src/main/java/com/eko/utils/StorageManager.kt +45 -45
- package/android/src/newarch/java/com/eko/RNBackgroundDownloaderModule.kt +18 -70
- package/android/src/oldarch/java/com/eko/RNBackgroundDownloaderModule.kt +18 -70
- package/ios/RNBackgroundDownloader.mm +187 -91
- package/lib/DownloadTask.js +8 -7
- package/lib/UploadTask.js +11 -10
- package/lib/config.d.ts +1 -10
- package/lib/config.js +1 -44
- package/lib/index.js +34 -32
- package/lib/logger.d.ts +2 -0
- package/lib/logger.js +16 -0
- package/lib/notifications.d.ts +8 -0
- package/lib/notifications.js +34 -0
- package/package.json +7 -3
- package/src/DownloadTask.ts +2 -1
- package/src/UploadTask.ts +2 -1
- package/src/config.ts +4 -45
- package/src/index.ts +3 -1
- package/src/logger.ts +16 -0
- package/src/notifications.ts +31 -0
|
@@ -14,6 +14,8 @@ import com.eko.handlers.OnBegin
|
|
|
14
14
|
import com.eko.handlers.OnProgress
|
|
15
15
|
import com.eko.handlers.OnProgressState
|
|
16
16
|
import com.eko.utils.HeaderUtils
|
|
17
|
+
import com.eko.utils.ReadableConverters
|
|
18
|
+
import com.eko.utils.RedirectResolver
|
|
17
19
|
import com.eko.utils.StorageManager
|
|
18
20
|
import com.facebook.react.bridge.Arguments
|
|
19
21
|
import com.facebook.react.bridge.Promise
|
|
@@ -25,8 +27,6 @@ import com.facebook.react.bridge.WritableMap
|
|
|
25
27
|
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
26
28
|
import org.json.JSONObject
|
|
27
29
|
import java.io.File
|
|
28
|
-
import java.net.HttpURLConnection
|
|
29
|
-
import java.net.URL
|
|
30
30
|
import java.util.concurrent.ExecutorService
|
|
31
31
|
import java.util.concurrent.Executors
|
|
32
32
|
import java.util.concurrent.Future
|
|
@@ -63,46 +63,6 @@ class RNBackgroundDownloaderModuleImpl(private val reactContext: ReactApplicatio
|
|
|
63
63
|
if (isLogsEnabled) Log.e(tag, message)
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
/**
|
|
67
|
-
* Convert a ReadableMap to JSONObject.
|
|
68
|
-
* Handles nested maps and arrays properly.
|
|
69
|
-
*/
|
|
70
|
-
fun readableMapToJsonObject(map: ReadableMap?): JSONObject? {
|
|
71
|
-
if (map == null) return null
|
|
72
|
-
val json = JSONObject()
|
|
73
|
-
val iterator = map.keySetIterator()
|
|
74
|
-
while (iterator.hasNextKey()) {
|
|
75
|
-
val key = iterator.nextKey()
|
|
76
|
-
when (map.getType(key)) {
|
|
77
|
-
ReadableType.Null -> json.put(key, JSONObject.NULL)
|
|
78
|
-
ReadableType.Boolean -> json.put(key, map.getBoolean(key))
|
|
79
|
-
ReadableType.Number -> json.put(key, map.getDouble(key))
|
|
80
|
-
ReadableType.String -> json.put(key, map.getString(key))
|
|
81
|
-
ReadableType.Map -> json.put(key, readableMapToJsonObject(map.getMap(key)))
|
|
82
|
-
ReadableType.Array -> json.put(key, readableArrayToJsonArray(map.getArray(key)))
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return json
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Convert a ReadableArray to JSONArray.
|
|
90
|
-
*/
|
|
91
|
-
private fun readableArrayToJsonArray(array: ReadableArray?): org.json.JSONArray? {
|
|
92
|
-
if (array == null) return null
|
|
93
|
-
val json = org.json.JSONArray()
|
|
94
|
-
for (i in 0 until array.size()) {
|
|
95
|
-
when (array.getType(i)) {
|
|
96
|
-
ReadableType.Null -> json.put(JSONObject.NULL)
|
|
97
|
-
ReadableType.Boolean -> json.put(array.getBoolean(i))
|
|
98
|
-
ReadableType.Number -> json.put(array.getDouble(i))
|
|
99
|
-
ReadableType.String -> json.put(array.getString(i))
|
|
100
|
-
ReadableType.Map -> json.put(readableMapToJsonObject(array.getMap(i)))
|
|
101
|
-
ReadableType.Array -> json.put(readableArrayToJsonArray(array.getArray(i)))
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return json
|
|
105
|
-
}
|
|
106
66
|
}
|
|
107
67
|
|
|
108
68
|
// Storage manager for persistent state
|
|
@@ -160,6 +120,20 @@ class RNBackgroundDownloaderModuleImpl(private val reactContext: ReactApplicatio
|
|
|
160
120
|
// Map to store metadata for paused downloads
|
|
161
121
|
private val configIdToMetadata = mutableMapOf<String, String>()
|
|
162
122
|
|
|
123
|
+
// Map to store the metered-network permission per download so pause/resume and
|
|
124
|
+
// recovery snapshots keep the constraint that the download was started with
|
|
125
|
+
private val configIdToIsAllowedOverMetered = mutableMapOf<String, Boolean>()
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Resolve the metered-network permission for a download: the in-memory intent
|
|
129
|
+
* recorded at start wins, then the caller-supplied persisted source (UIDT job
|
|
130
|
+
* extras, download state or task config), then the permissive default. Keeps
|
|
131
|
+
* the precedence policy in one place for every pause/snapshot path.
|
|
132
|
+
*/
|
|
133
|
+
private fun resolveIsAllowedOverMetered(configId: String, persistedValue: Boolean?): Boolean {
|
|
134
|
+
return configIdToIsAllowedOverMetered[configId] ?: persistedValue ?: true
|
|
135
|
+
}
|
|
136
|
+
|
|
163
137
|
// Last time (ms) a recovery snapshot was persisted for a resumable download,
|
|
164
138
|
// used to throttle snapshot writes from the frequent progress callbacks.
|
|
165
139
|
private val configIdToLastSnapshotMs = mutableMapOf<String, Long>()
|
|
@@ -522,6 +496,7 @@ class RNBackgroundDownloaderModuleImpl(private val reactContext: ReactApplicatio
|
|
|
522
496
|
configIdToDownloadId.remove(configId)
|
|
523
497
|
configIdToHeaders.remove(configId)
|
|
524
498
|
configIdToMetadata.remove(configId)
|
|
499
|
+
configIdToIsAllowedOverMetered.remove(configId)
|
|
525
500
|
configIdToLastSnapshotMs.remove(configId)
|
|
526
501
|
progressReporter.clearDownloadState(configId)
|
|
527
502
|
// Drop any force-stop recovery snapshot for this download.
|
|
@@ -561,100 +536,29 @@ class RNBackgroundDownloaderModuleImpl(private val reactContext: ReactApplicatio
|
|
|
561
536
|
?: return
|
|
562
537
|
val headers = configIdToHeaders[configId] ?: state.headers
|
|
563
538
|
val metadata = configIdToMetadata[configId] ?: "{}"
|
|
539
|
+
// Persisted fallback: the UIDT job extras survive process death for jobs the
|
|
540
|
+
// JobScheduler restarted in a fresh process; the download state carries the
|
|
541
|
+
// flag on the foreground-service path.
|
|
542
|
+
val persistedIsAllowedOverMetered =
|
|
543
|
+
(if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
|
|
544
|
+
UIDTDownloadJobService.getJobIsAllowedOverMetered(configId)
|
|
545
|
+
else null)
|
|
546
|
+
?: state.isAllowedOverMetered
|
|
564
547
|
|
|
565
548
|
downloader.saveActiveDownloadSnapshot(
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
549
|
+
Downloader.PausedDownloadInfo(
|
|
550
|
+
configId = configId,
|
|
551
|
+
url = state.url,
|
|
552
|
+
destination = state.destination,
|
|
553
|
+
headers = headers,
|
|
554
|
+
bytesDownloaded = bytesDownloaded,
|
|
555
|
+
bytesTotal = bytesTotal,
|
|
556
|
+
metadata = metadata,
|
|
557
|
+
isAllowedOverMetered = resolveIsAllowedOverMetered(configId, persistedIsAllowedOverMetered)
|
|
558
|
+
)
|
|
573
559
|
)
|
|
574
560
|
}
|
|
575
561
|
|
|
576
|
-
/**
|
|
577
|
-
* Resolve redirects for a URL up to maxRedirects limit
|
|
578
|
-
* @param originalUrl The original URL to follow
|
|
579
|
-
* @param maxRedirects Maximum number of redirects to follow (0 means no redirect resolution)
|
|
580
|
-
* @param headers Headers to include in redirect resolution requests
|
|
581
|
-
* @return The final resolved URL, or original URL if maxRedirects is 0 or resolution fails
|
|
582
|
-
*/
|
|
583
|
-
private fun resolveRedirects(originalUrl: String, maxRedirects: Int, headers: ReadableMap?): String {
|
|
584
|
-
if (maxRedirects <= 0) {
|
|
585
|
-
return originalUrl
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
try {
|
|
589
|
-
var currentUrl = originalUrl
|
|
590
|
-
var redirectCount = 0
|
|
591
|
-
|
|
592
|
-
while (redirectCount < maxRedirects) {
|
|
593
|
-
val url = URL(currentUrl)
|
|
594
|
-
val connection = url.openConnection() as HttpURLConnection
|
|
595
|
-
|
|
596
|
-
// Add headers to the redirect resolution request
|
|
597
|
-
HeaderUtils.applyToConnection(connection, headers)
|
|
598
|
-
|
|
599
|
-
// Add default headers for consistency with DownloadManager
|
|
600
|
-
HeaderUtils.applyDefaultHeaders(connection, headers)
|
|
601
|
-
|
|
602
|
-
connection.instanceFollowRedirects = false
|
|
603
|
-
connection.requestMethod = "HEAD" // Use HEAD to avoid downloading content
|
|
604
|
-
connection.connectTimeout = DownloadConstants.REDIRECT_TIMEOUT_MS
|
|
605
|
-
connection.readTimeout = DownloadConstants.REDIRECT_TIMEOUT_MS
|
|
606
|
-
|
|
607
|
-
val responseCode = connection.responseCode
|
|
608
|
-
|
|
609
|
-
if (responseCode in 300..399) {
|
|
610
|
-
// This is a redirect
|
|
611
|
-
val location = connection.getHeaderField("Location")
|
|
612
|
-
if (location == null) {
|
|
613
|
-
logW(NAME, "Redirect response without Location header at: $currentUrl")
|
|
614
|
-
break
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
// Handle relative URLs
|
|
618
|
-
currentUrl = when {
|
|
619
|
-
location.startsWith("/") -> {
|
|
620
|
-
val baseUrl = URL(currentUrl)
|
|
621
|
-
"${baseUrl.protocol}://${baseUrl.host}$location"
|
|
622
|
-
}
|
|
623
|
-
!location.startsWith("http") -> {
|
|
624
|
-
val baseUrl = URL(currentUrl)
|
|
625
|
-
"${baseUrl.protocol}://${baseUrl.host}/$location"
|
|
626
|
-
}
|
|
627
|
-
else -> location
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
logD(NAME, "Redirect ${redirectCount + 1}/$maxRedirects: $currentUrl -> $location")
|
|
631
|
-
redirectCount++
|
|
632
|
-
} else {
|
|
633
|
-
// Not a redirect, we've found the final URL
|
|
634
|
-
break
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
connection.disconnect()
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
if (redirectCount >= maxRedirects) {
|
|
641
|
-
logW(
|
|
642
|
-
NAME,
|
|
643
|
-
"Reached maximum redirects ($maxRedirects) for URL: $originalUrl. Final URL: $currentUrl"
|
|
644
|
-
)
|
|
645
|
-
} else {
|
|
646
|
-
logD(NAME, "Resolved URL after $redirectCount redirects: $currentUrl")
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
return currentUrl
|
|
650
|
-
|
|
651
|
-
} catch (e: Exception) {
|
|
652
|
-
logE(NAME, "Failed to resolve redirects for URL: $originalUrl. Error: ${e.message}")
|
|
653
|
-
// Return original URL if redirect resolution fails
|
|
654
|
-
return originalUrl
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
|
|
658
562
|
fun download(options: ReadableMap) {
|
|
659
563
|
// Ensure event emitter is initialized before starting download
|
|
660
564
|
// This fixes issues on first app install where download() might be called
|
|
@@ -678,7 +582,7 @@ class RNBackgroundDownloaderModuleImpl(private val reactContext: ReactApplicatio
|
|
|
678
582
|
// If passed as object, convert to JSON string properly
|
|
679
583
|
try {
|
|
680
584
|
val map = options.getMap("metadata")
|
|
681
|
-
|
|
585
|
+
ReadableConverters.toJsonObject(map)?.toString() ?: "{}"
|
|
682
586
|
} catch (e: Exception) {
|
|
683
587
|
logW(NAME, "Failed to convert metadata map to string: ${e.message}")
|
|
684
588
|
"{}"
|
|
@@ -726,7 +630,7 @@ class RNBackgroundDownloaderModuleImpl(private val reactContext: ReactApplicatio
|
|
|
726
630
|
// Resolve redirects if maxRedirects is specified
|
|
727
631
|
if (maxRedirects > 0) {
|
|
728
632
|
logD(NAME, "Resolving redirects for URL: $url (maxRedirects: $maxRedirects)")
|
|
729
|
-
url =
|
|
633
|
+
url = RedirectResolver.resolve(url, maxRedirects, headers)
|
|
730
634
|
logD(NAME, "Final resolved URL: $url")
|
|
731
635
|
}
|
|
732
636
|
|
|
@@ -775,7 +679,7 @@ class RNBackgroundDownloaderModuleImpl(private val reactContext: ReactApplicatio
|
|
|
775
679
|
|
|
776
680
|
// Helper function to start download with DownloadManager and track state
|
|
777
681
|
fun startDownloadManagerDownload(downloadId: Long) {
|
|
778
|
-
val config = RNBGDTaskConfig(id, url, destination, metadataValue)
|
|
682
|
+
val config = RNBGDTaskConfig(id, url, destination, metadataValue, isAllowedOverMetered = isAllowedOverMetered)
|
|
779
683
|
synchronized(sharedLock) {
|
|
780
684
|
// Clean up any stale state from previous downloads with the same ID
|
|
781
685
|
downloader.cleanupStaleState(id)
|
|
@@ -785,6 +689,7 @@ class RNBackgroundDownloaderModuleImpl(private val reactContext: ReactApplicatio
|
|
|
785
689
|
configIdToDownloadId[id] = downloadId
|
|
786
690
|
configIdToHeaders[id] = headersMap
|
|
787
691
|
configIdToMetadata[id] = metadataValue
|
|
692
|
+
configIdToIsAllowedOverMetered[id] = isAllowedOverMetered
|
|
788
693
|
downloadIdToConfig[downloadId] = config
|
|
789
694
|
saveDownloadIdToConfigMap()
|
|
790
695
|
resumeTasks(downloadId, config)
|
|
@@ -793,6 +698,16 @@ class RNBackgroundDownloaderModuleImpl(private val reactContext: ReactApplicatio
|
|
|
793
698
|
|
|
794
699
|
// Helper function to fall back to ResumableDownloader
|
|
795
700
|
fun startWithResumableDownloader() {
|
|
701
|
+
val spec = Downloader.PausedDownloadInfo(
|
|
702
|
+
configId = id,
|
|
703
|
+
url = url,
|
|
704
|
+
destination = destination,
|
|
705
|
+
headers = headersMap,
|
|
706
|
+
bytesDownloaded = 0L,
|
|
707
|
+
bytesTotal = -1L,
|
|
708
|
+
metadata = metadataValue,
|
|
709
|
+
isAllowedOverMetered = isAllowedOverMetered
|
|
710
|
+
)
|
|
796
711
|
synchronized(sharedLock) {
|
|
797
712
|
// Clean up any stale state from previous downloads with the same ID
|
|
798
713
|
downloader.cleanupStaleState(id)
|
|
@@ -801,8 +716,15 @@ class RNBackgroundDownloaderModuleImpl(private val reactContext: ReactApplicatio
|
|
|
801
716
|
progressReporter.initializeDownload(id)
|
|
802
717
|
configIdToHeaders[id] = headersMap
|
|
803
718
|
configIdToMetadata[id] = metadataValue
|
|
719
|
+
configIdToIsAllowedOverMetered[id] = isAllowedOverMetered
|
|
720
|
+
// Persist an initial recovery snapshot right away: progress-driven
|
|
721
|
+
// snapshots only start with the first received byte, so without this a
|
|
722
|
+
// download parked at 0 bytes (e.g. waiting for an unmetered network)
|
|
723
|
+
// would vanish without a trace if the app is force-stopped.
|
|
724
|
+
downloader.saveActiveDownloadSnapshot(spec)
|
|
725
|
+
configIdToLastSnapshotMs[id] = System.currentTimeMillis()
|
|
804
726
|
}
|
|
805
|
-
downloader.startResumableDownload(
|
|
727
|
+
downloader.startResumableDownload(spec, resumableDownloadListener)
|
|
806
728
|
}
|
|
807
729
|
|
|
808
730
|
// On Android 16+ (API 36), DownloadManager has strict path restrictions and throws
|
|
@@ -858,10 +780,14 @@ class RNBackgroundDownloaderModuleImpl(private val reactContext: ReactApplicatio
|
|
|
858
780
|
if (downloader.isResumableDownload(configId)) {
|
|
859
781
|
// Get state before pausing - check both UIDT jobs and regular service
|
|
860
782
|
var state: ResumableDownloader.DownloadState? = null
|
|
783
|
+
var uidtIsAllowedOverMetered: Boolean? = null
|
|
861
784
|
|
|
862
785
|
// Check UIDT jobs first (Android 14+)
|
|
863
786
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
|
864
787
|
state = UIDTDownloadJobService.getJobDownloadState(configId)
|
|
788
|
+
// Read from the job extras before pausing - pausing removes the job
|
|
789
|
+
// (and its extras) from the registry
|
|
790
|
+
uidtIsAllowedOverMetered = UIDTDownloadJobService.getJobIsAllowedOverMetered(configId)
|
|
865
791
|
}
|
|
866
792
|
|
|
867
793
|
// Fall back to regular service if not found in UIDT jobs
|
|
@@ -878,13 +804,19 @@ class RNBackgroundDownloaderModuleImpl(private val reactContext: ReactApplicatio
|
|
|
878
804
|
val metadata = configIdToMetadata[configId] ?: "{}"
|
|
879
805
|
|
|
880
806
|
downloader.savePausedDownloadState(
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
807
|
+
Downloader.PausedDownloadInfo(
|
|
808
|
+
configId = configId,
|
|
809
|
+
url = state.url,
|
|
810
|
+
destination = state.destination,
|
|
811
|
+
headers = headers,
|
|
812
|
+
bytesDownloaded = state.bytesDownloaded.get(),
|
|
813
|
+
bytesTotal = state.bytesTotal,
|
|
814
|
+
metadata = metadata,
|
|
815
|
+
isAllowedOverMetered = resolveIsAllowedOverMetered(
|
|
816
|
+
configId,
|
|
817
|
+
uidtIsAllowedOverMetered ?: state.isAllowedOverMetered
|
|
818
|
+
)
|
|
819
|
+
)
|
|
888
820
|
)
|
|
889
821
|
|
|
890
822
|
// Now tracked as an explicit paused download - drop the recovery snapshot.
|
|
@@ -903,12 +835,13 @@ class RNBackgroundDownloaderModuleImpl(private val reactContext: ReactApplicatio
|
|
|
903
835
|
if (config != null) {
|
|
904
836
|
val headers = configIdToHeaders[configId] ?: emptyMap()
|
|
905
837
|
val metadata = configIdToMetadata[configId] ?: config.metadata
|
|
838
|
+
val isAllowedOverMetered = resolveIsAllowedOverMetered(configId, config.isAllowedOverMetered)
|
|
906
839
|
|
|
907
840
|
// Stop progress tracking
|
|
908
841
|
stopTaskProgress(configId)
|
|
909
842
|
|
|
910
843
|
// Pause the download (this cancels DownloadManager and saves state)
|
|
911
|
-
val paused = downloader.pause(downloadId, configId, config.url, config.destination, headers, metadata)
|
|
844
|
+
val paused = downloader.pause(downloadId, configId, config.url, config.destination, headers, metadata, isAllowedOverMetered)
|
|
912
845
|
|
|
913
846
|
if (paused) {
|
|
914
847
|
// Remove from DownloadManager tracking
|
|
@@ -918,6 +851,31 @@ class RNBackgroundDownloaderModuleImpl(private val reactContext: ReactApplicatio
|
|
|
918
851
|
logD(NAME, "Paused DownloadManager download: $configId")
|
|
919
852
|
}
|
|
920
853
|
}
|
|
854
|
+
return
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
// Finally, check for a UIDT job that is scheduled but not yet running -
|
|
858
|
+
// e.g. held pending by its unmetered-network constraint. Such a job is
|
|
859
|
+
// invisible to the branches above (no registry entry until onStartJob),
|
|
860
|
+
// and without this it would start downloading despite the user's pause
|
|
861
|
+
// once its network constraint is satisfied.
|
|
862
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
|
863
|
+
val pending = UIDTDownloadJobService.cancelPendingJob(reactContext, configId)
|
|
864
|
+
if (pending != null) {
|
|
865
|
+
downloader.savePausedDownloadState(
|
|
866
|
+
Downloader.PausedDownloadInfo(
|
|
867
|
+
configId = configId,
|
|
868
|
+
url = pending.url,
|
|
869
|
+
destination = pending.destination,
|
|
870
|
+
headers = configIdToHeaders[configId] ?: pending.headers,
|
|
871
|
+
bytesDownloaded = pending.startByte,
|
|
872
|
+
bytesTotal = pending.totalBytes,
|
|
873
|
+
metadata = configIdToMetadata[configId] ?: pending.metadata,
|
|
874
|
+
isAllowedOverMetered = pending.isAllowedOverMetered
|
|
875
|
+
)
|
|
876
|
+
)
|
|
877
|
+
logD(NAME, "Paused pending UIDT job: $configId at byte ${pending.startByte}")
|
|
878
|
+
}
|
|
921
879
|
}
|
|
922
880
|
}
|
|
923
881
|
}
|
|
@@ -1355,7 +1313,7 @@ class RNBackgroundDownloaderModuleImpl(private val reactContext: ReactApplicatio
|
|
|
1355
1313
|
ReadableType.Map -> {
|
|
1356
1314
|
try {
|
|
1357
1315
|
val map = options.getMap("metadata")
|
|
1358
|
-
|
|
1316
|
+
ReadableConverters.toJsonObject(map)?.toString() ?: "{}"
|
|
1359
1317
|
} catch (e: Exception) {
|
|
1360
1318
|
logW(NAME, "Failed to convert metadata map to string: ${e.message}")
|
|
1361
1319
|
"{}"
|