Skip to content

Commit

Permalink
Late init edu eval
Browse files Browse the repository at this point in the history
  • Loading branch information
qhy040404 committed Jun 30, 2023
1 parent dc9ee4e commit 815db64
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,22 @@ class GradesActivity : BaseEduActivity(), MenuProvider {
}
).apply {
if (this.courses.isEmpty()) {
delay(500)
if (!Requests.initEduEval()) {
delay(500L)
if (!Requests.initEduEval()) return@apply
}
delay(500L)

val token =
CookieJarImpl.loadForRequest(URLManager.EDU_DOMAIN.toHttpUrl())
.find { it.name == "student_evaluation_token" }?.value
if (token.isNullOrEmpty()) return@apply

val evaluationTasks =
Requests.get(
URLManager.getEduEvaluationTaskUrl(this.id),
mapOf(
"Authorization" to CookieJarImpl.loadForRequest(URLManager.EDU_DOMAIN.toHttpUrl())
.find { it.name == "student_evaluation_token" }?.value.orEmpty()
"Authorization" to token
).toHeaders()
)
val evalTasksObj = JSONObject(evaluationTasks).optJSONArray("data")!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,16 +320,13 @@ object Requests {
URLManager.EDU_CHECK_URL,
shouldHas = "person"
).also {
if (it) {
initEduEval()
}
eduInitialized = it
return it
}
}
}

private fun initEduEval() {
fun initEduEval(): Boolean {
val initToken = get(URLManager.EDU_EVALUATION_URL).substringBetween("token=", "';")
val finalToken = post(
URLManager.EDU_EVALUATION_TOKEN_URL,
Expand All @@ -348,5 +345,7 @@ object Requests {
.hostOnlyDomain(url.host).build()
)
)
return !CookieJarImpl.loadForRequest(url)
.find { it.name == "student_evaluation_token" }?.value.isNullOrEmpty()
}
}

0 comments on commit 815db64

Please sign in to comment.