Metadata support added for DownloadTask. Android & Ios

This commit is contained in:
Tolgahan Çelik
2022-07-26 17:32:23 +03:00
parent e0355e7f79
commit d19b9c9a72
6 changed files with 36 additions and 6 deletions
+14
View File
@@ -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;
}
}
}