forked from github/szkolny
[API/Librus] Make downloading attachments use Synergia.
This commit is contained in:
parent
328b20f78b
commit
a6ce3a5068
@ -57,6 +57,7 @@ const val LIBRUS_MESSAGES_URL = "https://wiadomosci.librus.pl/module"
|
|||||||
const val LIBRUS_SANDBOX_URL = "https://sandbox.librus.pl/index.php?action="
|
const val LIBRUS_SANDBOX_URL = "https://sandbox.librus.pl/index.php?action="
|
||||||
|
|
||||||
const val LIBRUS_SYNERGIA_HOMEWORK_ATTACHMENT_URL = "https://synergia.librus.pl/homework/downloadFile"
|
const val LIBRUS_SYNERGIA_HOMEWORK_ATTACHMENT_URL = "https://synergia.librus.pl/homework/downloadFile"
|
||||||
|
const val LIBRUS_SYNERGIA_MESSAGES_ATTACHMENT_URL = "https://synergia.librus.pl/wiadomosci/pobierz_zalacznik"
|
||||||
|
|
||||||
const val IDZIENNIK_USER_AGENT = SYNERGIA_USER_AGENT
|
const val IDZIENNIK_USER_AGENT = SYNERGIA_USER_AGENT
|
||||||
const val IDZIENNIK_WEB_URL = "https://iuczniowie.progman.pl/idziennik"
|
const val IDZIENNIK_WEB_URL = "https://iuczniowie.progman.pl/idziennik"
|
||||||
|
@ -9,13 +9,9 @@ import pl.szczodrzynski.edziennik.App
|
|||||||
import pl.szczodrzynski.edziennik.data.api.*
|
import pl.szczodrzynski.edziennik.data.api.*
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusData
|
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusData
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.api.LibrusApiAnnouncementMarkAsRead
|
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.api.LibrusApiAnnouncementMarkAsRead
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.messages.LibrusMessagesGetAttachment
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.messages.LibrusMessagesGetMessage
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.messages.LibrusMessagesGetRecipientList
|
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.messages.LibrusMessagesGetRecipientList
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.messages.LibrusMessagesSendMessage
|
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.messages.LibrusMessagesSendMessage
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.synergia.LibrusSynergiaGetHomework
|
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.synergia.*
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.synergia.LibrusSynergiaHomeworkGetAttachment
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.synergia.LibrusSynergiaMarkAllAnnouncementsAsRead
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.firstlogin.LibrusFirstLogin
|
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.firstlogin.LibrusFirstLogin
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.login.LibrusLogin
|
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.login.LibrusLogin
|
||||||
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback
|
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback
|
||||||
@ -124,8 +120,8 @@ class Librus(val app: App, val profile: Profile?, val loginStore: LoginStore, va
|
|||||||
override fun getAttachment(owner: Any, attachmentId: Long, attachmentName: String) {
|
override fun getAttachment(owner: Any, attachmentId: Long, attachmentName: String) {
|
||||||
when (owner) {
|
when (owner) {
|
||||||
is Message -> {
|
is Message -> {
|
||||||
login(LOGIN_METHOD_LIBRUS_MESSAGES) {
|
login(LOGIN_METHOD_LIBRUS_SYNERGIA) {
|
||||||
LibrusMessagesGetAttachment(data, owner, attachmentId, attachmentName) {
|
LibrusSynergiaGetAttachment(data, owner, attachmentId, attachmentName) {
|
||||||
completed()
|
completed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,6 +91,8 @@ open class LibrusSynergia(open val data: DataLibrus, open val lastSync: Long?) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun redirectUrlGet(tag: String, url: String, onSuccess: (url: String) -> Unit) {
|
fun redirectUrlGet(tag: String, url: String, onSuccess: (url: String) -> Unit) {
|
||||||
|
d(tag, "Request: Librus/Synergia - $url")
|
||||||
|
|
||||||
val callback = object : TextCallbackHandler() {
|
val callback = object : TextCallbackHandler() {
|
||||||
override fun onSuccess(text: String?, response: Response) {
|
override fun onSuccess(text: String?, response: Response) {
|
||||||
val redirectUrl = response.headers().get("Location")
|
val redirectUrl = response.headers().get("Location")
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
package pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.synergia
|
||||||
|
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.LIBRUS_SYNERGIA_MESSAGES_ATTACHMENT_URL
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.DataLibrus
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.LibrusSynergia
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.librus.data.messages.LibrusSandboxDownloadAttachment
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.entity.Message
|
||||||
|
|
||||||
|
class LibrusSynergiaGetAttachment(override val data: DataLibrus,
|
||||||
|
val message: Message,
|
||||||
|
val attachmentId: Long,
|
||||||
|
val attachmentName: String,
|
||||||
|
val onSuccess: () -> Unit
|
||||||
|
) : LibrusSynergia(data, null) {
|
||||||
|
companion object {
|
||||||
|
const val TAG = "LibrusSynergiaGetAttachment"
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
redirectUrlGet(TAG, "$LIBRUS_SYNERGIA_MESSAGES_ATTACHMENT_URL/${message.id}/$attachmentId") { url ->
|
||||||
|
LibrusSandboxDownloadAttachment(data, url, message, attachmentId, attachmentName, onSuccess)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user