eslint files

This commit is contained in:
Kesha Antonov
2023-01-30 00:37:55 +03:00
parent 4c56764f16
commit 5e93648431
5 changed files with 230 additions and 200 deletions
+76 -76
View File
@@ -9,97 +9,97 @@ function validateHandler (handler) {
}
export default class DownloadTask {
state = 'PENDING'
percent = 0
bytesWritten = 0
totalBytes = 0
metadata = {}
state = 'PENDING'
percent = 0
bytesWritten = 0
totalBytes = 0
metadata = {}
constructor (taskInfo, originalTask) {
this.id = taskInfo.id
this.percent = taskInfo.percent ?? 0
this.bytesWritten = taskInfo.bytesWritten ?? 0
this.totalBytes = taskInfo.totalBytes ?? 0
constructor (taskInfo, originalTask) {
this.id = taskInfo.id
this.percent = taskInfo.percent ?? 0
this.bytesWritten = taskInfo.bytesWritten ?? 0
this.totalBytes = taskInfo.totalBytes ?? 0
this.metadata = this.tryParseJson(taskInfo.metadata)
this.metadata = this.tryParseJson(taskInfo.metadata)
if (originalTask) {
this.beginHandler = originalTask.beginHandler
this.progressHandler = originalTask.progressHandler
this.doneHandler = originalTask.doneHandler
this.errorHandler = originalTask.errorHandler
}
if (originalTask) {
this.beginHandler = originalTask.beginHandler
this.progressHandler = originalTask.progressHandler
this.doneHandler = originalTask.doneHandler
this.errorHandler = originalTask.errorHandler
}
}
begin (handler) {
validateHandler(handler)
this.beginHandler = handler
return this
}
begin (handler) {
validateHandler(handler)
this.beginHandler = handler
return this
}
progress (handler) {
validateHandler(handler)
this.progressHandler = handler
return this
}
progress (handler) {
validateHandler(handler)
this.progressHandler = handler
return this
}
done (handler) {
validateHandler(handler)
this.doneHandler = handler
return this
}
done (handler) {
validateHandler(handler)
this.doneHandler = handler
return this
}
error (handler) {
validateHandler(handler)
this.errorHandler = handler
return this
}
error (handler) {
validateHandler(handler)
this.errorHandler = handler
return this
}
onBegin ({ expectedBytes, headers }) {
this.state = 'DOWNLOADING'
this?.beginHandler({ expectedBytes, headers })
}
onBegin ({ expectedBytes, headers }) {
this.state = 'DOWNLOADING'
this?.beginHandler({ expectedBytes, headers })
}
onProgress (percent, bytesWritten, totalBytes) {
this.percent = percent
this.bytesWritten = bytesWritten
this.totalBytes = totalBytes
this?.progressHandler(percent, bytesWritten, totalBytes)
}
onProgress (percent, bytesWritten, totalBytes) {
this.percent = percent
this.bytesWritten = bytesWritten
this.totalBytes = totalBytes
this?.progressHandler(percent, bytesWritten, totalBytes)
}
onDone ({ location }) {
this.state = 'DONE'
this?.doneHandler({ location })
}
onDone ({ location }) {
this.state = 'DONE'
this?.doneHandler({ location })
}
onError (error, errorCode) {
this.state = 'FAILED'
this?.errorHandler(error, errorCode)
}
onError (error, errorCode) {
this.state = 'FAILED'
this?.errorHandler(error, errorCode)
}
pause () {
this.state = 'PAUSED'
RNBackgroundDownloader.pauseTask(this.id)
}
pause () {
this.state = 'PAUSED'
RNBackgroundDownloader.pauseTask(this.id)
}
resume () {
this.state = 'DOWNLOADING'
RNBackgroundDownloader.resumeTask(this.id)
}
resume () {
this.state = 'DOWNLOADING'
RNBackgroundDownloader.resumeTask(this.id)
}
stop () {
this.state = 'STOPPED'
RNBackgroundDownloader.stopTask(this.id)
}
stop () {
this.state = 'STOPPED'
RNBackgroundDownloader.stopTask(this.id)
}
tryParseJson (element) {
try {
if (element)
element = JSON.parse(element)
return element
} catch (e) {
console.warn('DownloadTask tryParseJson', e)
return null
}
tryParseJson (element) {
try {
if (element)
element = JSON.parse(element)
return element
} catch (e) {
console.warn('DownloadTask tryParseJson', e)
return null
}
}
}