mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-02-07 16:44:37 +01:00
[API/Librus] Fix attachment downloading, once again.
This commit is contained in:
parent
c6e1ff2164
commit
6deb408d80
@ -253,6 +253,7 @@ open class LibrusMessages(open val data: DataLibrus, open val lastSync: Long?) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun sandboxGetFile(tag: String, url: String, targetFile: File, onSuccess: (file: File) -> Unit,
|
fun sandboxGetFile(tag: String, url: String, targetFile: File, onSuccess: (file: File) -> Unit,
|
||||||
|
method: Int = GET,
|
||||||
onProgress: (written: Long, total: Long) -> Unit) {
|
onProgress: (written: Long, total: Long) -> Unit) {
|
||||||
|
|
||||||
d(tag, "Request: Librus/Messages - $url")
|
d(tag, "Request: Librus/Messages - $url")
|
||||||
@ -291,9 +292,14 @@ open class LibrusMessages(open val data: DataLibrus, open val lastSync: Long?) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Request.builder()
|
Request.builder()
|
||||||
.url("$url")
|
.url(url)
|
||||||
.userAgent(SYNERGIA_USER_AGENT)
|
.userAgent(SYNERGIA_USER_AGENT)
|
||||||
.post()
|
.also {
|
||||||
|
when (method) {
|
||||||
|
POST -> it.post()
|
||||||
|
else -> it.get()
|
||||||
|
}
|
||||||
|
}
|
||||||
.callback(callback)
|
.callback(callback)
|
||||||
.build()
|
.build()
|
||||||
.enqueue()
|
.enqueue()
|
||||||
|
@ -6,10 +6,7 @@ package pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.messages
|
|||||||
|
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import org.greenrobot.eventbus.EventBus
|
import org.greenrobot.eventbus.EventBus
|
||||||
import pl.szczodrzynski.edziennik.data.api.ERROR_FILE_DOWNLOAD
|
import pl.szczodrzynski.edziennik.data.api.*
|
||||||
import pl.szczodrzynski.edziennik.data.api.EXCEPTION_LIBRUS_MESSAGES_REQUEST
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.LIBRUS_SANDBOX_URL
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.Regexes
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.DataLibrus
|
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.DataLibrus
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusMessages
|
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusMessages
|
||||||
import pl.szczodrzynski.edziennik.data.api.events.AttachmentGetEvent
|
import pl.szczodrzynski.edziennik.data.api.events.AttachmentGetEvent
|
||||||
@ -54,10 +51,10 @@ class LibrusMessagesGetAttachment(override val data: DataLibrus,
|
|||||||
|
|
||||||
val attachmentKey = keyMatcher[1]
|
val attachmentKey = keyMatcher[1]
|
||||||
getAttachmentCheckKey(attachmentKey) {
|
getAttachmentCheckKey(attachmentKey) {
|
||||||
downloadAttachment("${LIBRUS_SANDBOX_URL}CSDownload&singleUseKey=$attachmentKey")
|
downloadAttachment("${LIBRUS_SANDBOX_URL}CSDownload&singleUseKey=$attachmentKey", method = POST)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
downloadAttachment(downloadLink)
|
downloadAttachment(downloadLink, method = GET)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,7 +88,7 @@ class LibrusMessagesGetAttachment(override val data: DataLibrus,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun downloadAttachment(url: String) {
|
private fun downloadAttachment(url: String, method: Int = GET) {
|
||||||
val targetFile = File(Utils.getStorageDir(), attachmentName)
|
val targetFile = File(Utils.getStorageDir(), attachmentName)
|
||||||
|
|
||||||
sandboxGetFile(TAG, url, targetFile, { file ->
|
sandboxGetFile(TAG, url, targetFile, { file ->
|
||||||
|
Loading…
x
Reference in New Issue
Block a user