Add rate limiting to Viz (#7050)

* Add rate limiting to Viz.

* Fix NPE at logged in check.
This commit is contained in:
Alessandro Jean 2021-05-16 13:43:07 -03:00 committed by GitHub
parent 3a90e498b1
commit 91904eaaa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View File

@ -5,12 +5,13 @@ ext {
extName = 'VIZ Shonen Jump' extName = 'VIZ Shonen Jump'
pkgNameSuffix = 'en.vizshonenjump' pkgNameSuffix = 'en.vizshonenjump'
extClass = '.VizShonenJump' extClass = '.VizShonenJump'
extVersionCode = 8 extVersionCode = 9
libVersion = '1.2' libVersion = '1.2'
} }
dependencies { dependencies {
implementation 'com.drewnoakes:metadata-extractor:2.14.0' implementation 'com.drewnoakes:metadata-extractor:2.14.0'
implementation project(':lib-ratelimit')
} }
apply from: "$rootDir/common.gradle" apply from: "$rootDir/common.gradle"

View File

@ -1,6 +1,5 @@
package eu.kanade.tachiyomi.extension.en.vizshonenjump package eu.kanade.tachiyomi.extension.en.vizshonenjump
import com.github.salomonbrys.kotson.bool
import com.github.salomonbrys.kotson.get import com.github.salomonbrys.kotson.get
import com.github.salomonbrys.kotson.int import com.github.salomonbrys.kotson.int
import com.github.salomonbrys.kotson.nullInt import com.github.salomonbrys.kotson.nullInt
@ -8,6 +7,7 @@ import com.github.salomonbrys.kotson.nullObj
import com.github.salomonbrys.kotson.nullString import com.github.salomonbrys.kotson.nullString
import com.github.salomonbrys.kotson.obj import com.github.salomonbrys.kotson.obj
import com.google.gson.JsonParser import com.google.gson.JsonParser
import eu.kanade.tachiyomi.lib.ratelimit.RateLimitInterceptor
import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.model.MangasPage import eu.kanade.tachiyomi.source.model.MangasPage
@ -29,6 +29,7 @@ import rx.Observable
import java.text.ParseException import java.text.ParseException
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Locale import java.util.Locale
import java.util.concurrent.TimeUnit
class VizShonenJump : ParsedHttpSource() { class VizShonenJump : ParsedHttpSource() {
@ -44,6 +45,7 @@ class VizShonenJump : ParsedHttpSource() {
.addInterceptor(::authCheckIntercept) .addInterceptor(::authCheckIntercept)
.addInterceptor(::authChapterCheckIntercept) .addInterceptor(::authChapterCheckIntercept)
.addInterceptor(VizImageInterceptor()) .addInterceptor(VizImageInterceptor())
.addInterceptor(RateLimitInterceptor(1, 1, TimeUnit.SECONDS))
.build() .build()
override fun headersBuilder(): Headers.Builder = Headers.Builder() override fun headersBuilder(): Headers.Builder = Headers.Builder()
@ -281,8 +283,8 @@ class VizShonenJump : ParsedHttpSource() {
?: client.newCall(loginCheckRequest).execute() ?: client.newCall(loginCheckRequest).execute()
val document = loginCheckResponse.asJsoup() val document = loginCheckResponse.asJsoup()
loggedIn = document.select("div#o_account-links-content").first()!! loggedIn = document.select("div#o_account-links-content").firstOrNull()
.attr("logged_in")!!.toBoolean() ?.attr("logged_in")?.toBoolean() ?: false
loginCheckResponse.close() loginCheckResponse.close()
} }
@ -355,7 +357,7 @@ class VizShonenJump : ParsedHttpSource() {
companion object { companion object {
private const val ACCEPT_JSON = "application/json, text/javascript, */*; q=0.01" private const val ACCEPT_JSON = "application/json, text/javascript, */*; q=0.01"
private const val USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " + private const val USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " +
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36" "AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36"
private val DATE_FORMATTER by lazy { private val DATE_FORMATTER by lazy {
SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH) SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH)