Fix adding vToken headers during registration

This commit is contained in:
Mikołaj Pich 2024-05-12 14:46:11 +02:00
parent c1e40d8538
commit 5999e046e4
No known key found for this signature in database

View file

@ -345,25 +345,23 @@ internal class RegisterRepository(
private suspend fun getEduOneDiaries(baseStudentPlus: String, homepage: String): List<RegisterStudent> { private suspend fun getEduOneDiaries(baseStudentPlus: String, homepage: String): List<RegisterStudent> {
val moduleHeaders = getModuleHeadersFromDocument(homepage) val moduleHeaders = getModuleHeadersFromDocument(homepage)
val contextUrl = (baseStudentPlus + "api/Context") val contextUrl = (baseStudentPlus + "api/Context").toHttpUrl()
.toHttpUrl()
.mapModuleUrls(StudentPlusModuleHost, moduleHeaders.appVersion)
val contextVToken = contextUrl.getMatchedVToken(StudentPlusModuleHost, moduleHeaders) val contextVToken = contextUrl.getMatchedVToken(StudentPlusModuleHost, moduleHeaders)
val mappedContextUrl = contextUrl.mapModuleUrls(StudentPlusModuleHost, moduleHeaders.appVersion)
val semestersUrl = (baseStudentPlus + "api/OkresyKlasyfikacyjne") val semestersUrl = (baseStudentPlus + "api/OkresyKlasyfikacyjne").toHttpUrl()
.toHttpUrl()
.mapModuleUrls(StudentPlusModuleHost, moduleHeaders.appVersion)
val semestersVToken = semestersUrl.getMatchedVToken(StudentPlusModuleHost, moduleHeaders) val semestersVToken = semestersUrl.getMatchedVToken(StudentPlusModuleHost, moduleHeaders)
val mappedSemestersUrl = semestersUrl.mapModuleUrls(StudentPlusModuleHost, moduleHeaders.appVersion)
return studentPlus return studentPlus
.getContextByUrl(vToken = contextVToken, url = contextUrl.toString()).students .getContextByUrl(vToken = contextVToken, url = mappedContextUrl.toString()).students
.map { contextStudent -> .map { contextStudent ->
val semesters = runCatching { val semesters = runCatching {
when { when {
contextStudent.isAuthorizationRequired -> emptyList() contextStudent.isAuthorizationRequired -> emptyList()
else -> studentPlus.getSemestersByUrl( else -> studentPlus.getSemestersByUrl(
vToken = semestersVToken, vToken = semestersVToken,
url = semestersUrl.toString(), url = mappedSemestersUrl.toString(),
key = contextStudent.key, key = contextStudent.key,
diaryId = contextStudent.registerId, diaryId = contextStudent.registerId,
) )