mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-12-18 14:47:15 +00:00
fixes in tempUpload of js part
This commit is contained in:
parent
9cf01ab54f
commit
121e513fdd
@ -4,7 +4,10 @@ import dev.inmo.micro_utils.common.MPPFile
|
|||||||
import dev.inmo.micro_utils.ktor.common.TemporalFileId
|
import dev.inmo.micro_utils.ktor.common.TemporalFileId
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.HttpClient
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
|
import org.w3c.dom.mediasource.ENDED
|
||||||
|
import org.w3c.dom.mediasource.ReadyState
|
||||||
import org.w3c.xhr.*
|
import org.w3c.xhr.*
|
||||||
|
import org.w3c.xhr.XMLHttpRequest.Companion.DONE
|
||||||
|
|
||||||
suspend fun tempUpload(
|
suspend fun tempUpload(
|
||||||
fullTempUploadDraftPath: String,
|
fullTempUploadDraftPath: String,
|
||||||
@ -12,7 +15,7 @@ suspend fun tempUpload(
|
|||||||
onUpload: (Long, Long) -> Unit
|
onUpload: (Long, Long) -> Unit
|
||||||
): TemporalFileId {
|
): TemporalFileId {
|
||||||
val formData = FormData()
|
val formData = FormData()
|
||||||
val answer = CompletableDeferred<TemporalFileId>()
|
val answer = CompletableDeferred<TemporalFileId>(currentCoroutineContext().job)
|
||||||
|
|
||||||
formData.append(
|
formData.append(
|
||||||
"data",
|
"data",
|
||||||
@ -37,17 +40,15 @@ suspend fun tempUpload(
|
|||||||
request.open("POST", fullTempUploadDraftPath, true)
|
request.open("POST", fullTempUploadDraftPath, true)
|
||||||
request.send(formData)
|
request.send(formData)
|
||||||
|
|
||||||
val handle = currentCoroutineContext().job.invokeOnCompletion {
|
answer.invokeOnCompletion {
|
||||||
runCatching {
|
runCatching {
|
||||||
request.abort()
|
if (request.readyState != DONE) {
|
||||||
|
request.abort()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return runCatching {
|
return answer.await()
|
||||||
answer.await()
|
|
||||||
}.also {
|
|
||||||
handle.dispose()
|
|
||||||
}.getOrThrow()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user