mirror of
https://github.com/zoriya/react-native-background-downloader.git
synced 2026-06-08 12:00:49 +00:00
Metadata support added for DownloadTask. Android & Ios
This commit is contained in:
@@ -10,6 +10,7 @@ export default class DownloadTask {
|
||||
percent = 0
|
||||
bytesWritten = 0
|
||||
totalBytes = 0
|
||||
metadata = {}
|
||||
|
||||
constructor (taskInfo, originalTask) {
|
||||
if (typeof taskInfo === 'string') {
|
||||
@@ -19,6 +20,10 @@ export default class DownloadTask {
|
||||
this.percent = taskInfo.percent
|
||||
this.bytesWritten = taskInfo.bytesWritten
|
||||
this.totalBytes = taskInfo.totalBytes
|
||||
|
||||
if (this.#parseable(taskInfo.metadata)) {
|
||||
this.metadata = JSON.parse(taskInfo.metadata);
|
||||
}
|
||||
}
|
||||
|
||||
if (originalTask) {
|
||||
@@ -93,4 +98,13 @@ export default class DownloadTask {
|
||||
this.state = 'STOPPED'
|
||||
RNBackgroundDownloader.stopTask(this.id)
|
||||
}
|
||||
|
||||
#parseable = (element) => {
|
||||
try {
|
||||
JSON.parse(element);
|
||||
return true;
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user