Fix JSON error when loading chapter at Viz. (#6774)

This commit is contained in:
Alessandro Jean 2021-04-30 23:04:23 -03:00 committed by GitHub
parent b2fc487395
commit 58d5923290
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 17 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'VIZ Shonen Jump'
pkgNameSuffix = 'en.vizshonenjump'
extClass = '.VizShonenJump'
extVersionCode = 7
extVersionCode = 8
libVersion = '1.2'
}

View File

@ -3,7 +3,9 @@ package eu.kanade.tachiyomi.extension.en.vizshonenjump
import com.github.salomonbrys.kotson.bool
import com.github.salomonbrys.kotson.get
import com.github.salomonbrys.kotson.int
import com.github.salomonbrys.kotson.nullInt
import com.github.salomonbrys.kotson.nullObj
import com.github.salomonbrys.kotson.nullString
import com.github.salomonbrys.kotson.obj
import com.google.gson.JsonParser
import eu.kanade.tachiyomi.network.GET
@ -158,6 +160,8 @@ class VizShonenJump : ParsedHttpSource() {
override fun chapterListParse(response: Response): List<SChapter> {
val allChapters = super.chapterListParse(response)
checkIfIsLoggedIn()
if (loggedIn == true) {
return allChapters.map { oldChapter ->
oldChapter.apply {
@ -267,14 +271,14 @@ class VizShonenJump : ParsedHttpSource() {
return GET(newImageUrl, newHeaders)
}
private fun authCheckIntercept(chain: Interceptor.Chain): Response {
if (loggedIn == null) {
private fun checkIfIsLoggedIn(chain: Interceptor.Chain? = null) {
val refreshHeaders = headersBuilder()
.add("X-Requested-With", "XMLHttpRequest")
.build()
val loginCheckRequest = GET("$baseUrl/$REFRESH_LOGIN_LINKS_URL", refreshHeaders)
val loginCheckResponse = chain.proceed(loginCheckRequest)
val loginCheckResponse = chain?.proceed(loginCheckRequest)
?: client.newCall(loginCheckRequest).execute()
val document = loginCheckResponse.asJsoup()
loggedIn = document.select("div#o_account-links-content").first()!!
@ -283,6 +287,11 @@ class VizShonenJump : ParsedHttpSource() {
loginCheckResponse.close()
}
private fun authCheckIntercept(chain: Interceptor.Chain): Response {
if (loggedIn == null) {
checkIfIsLoggedIn(chain)
}
return chain.proceed(chain.request())
}
@ -311,7 +320,7 @@ class VizShonenJump : ParsedHttpSource() {
authCheckResponse.close()
if (authCheckJson["ok"].bool && authCheckJson["archive_info"]["ok"].bool) {
if (authCheckJson["ok"].int == 1 && authCheckJson["archive_info"]["ok"].int == 1) {
val newChapterUrl = chain.request().url.newBuilder()
.removeAllQueryParameters("locked")
.build()
@ -323,14 +332,16 @@ class VizShonenJump : ParsedHttpSource() {
}
if (
authCheckJson["archive_info"]["err"].nullObj != null &&
authCheckJson["archive_info"]["err"]["code"].int == 4 &&
authCheckJson["archive_info"]["err"].isJsonObject &&
authCheckJson["archive_info"]["err"]["code"].nullInt == 4 &&
loggedIn == true
) {
throw Exception(SESSION_EXPIRED)
}
throw Exception(AUTH_CHECK_FAILED)
val errorMessage = authCheckJson["archive_info"]["err"].nullObj?.get("msg")?.nullString
throw Exception(errorMessage ?: AUTH_CHECK_FAILED)
}
private fun String.toDate(): Long {