Make rate limiting apply to all requests in MH (#6542)
* Make rate limit apply to images in MH. * Update block message.
This commit is contained in:
		
							parent
							
								
									42a1284781
								
							
						
					
					
						commit
						08e71f3454
					
				| @ -5,7 +5,7 @@ ext { | ||||
|     extName = 'Mangá Host' | ||||
|     pkgNameSuffix = 'pt.mangahost' | ||||
|     extClass = '.MangaHost' | ||||
|     extVersionCode = 22 | ||||
|     extVersionCode = 23 | ||||
|     libVersion = '1.2' | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -38,11 +38,10 @@ class MangaHost : ParsedHttpSource() { | ||||
|     override val supportsLatest = true | ||||
| 
 | ||||
|     override val client: OkHttpClient = network.cloudflareClient.newBuilder() | ||||
|         .addInterceptor(::rateLimitIntercept) | ||||
|         .addInterceptor(RateLimitInterceptor(1, 3, TimeUnit.SECONDS)) | ||||
|         .addInterceptor(::blockMessageIntercept) | ||||
|         .build() | ||||
| 
 | ||||
|     private val rateLimitInterceptor = RateLimitInterceptor(1, 3, TimeUnit.SECONDS) | ||||
| 
 | ||||
|     override fun headersBuilder(): Headers.Builder = Headers.Builder() | ||||
|         .add("Accept", ACCEPT) | ||||
|         .add("Accept-Language", ACCEPT_LANGUAGE) | ||||
| @ -197,12 +196,15 @@ class MangaHost : ParsedHttpSource() { | ||||
|         return GET(page.imageUrl!!, newHeaders) | ||||
|     } | ||||
| 
 | ||||
|     private fun rateLimitIntercept(chain: Interceptor.Chain): Response { | ||||
|         return if (chain.request().url().toString().contains(CDN_REGEX)) { | ||||
|             chain.proceed(chain.request()) | ||||
|         } else { | ||||
|             rateLimitInterceptor.intercept(chain) | ||||
|     private fun blockMessageIntercept(chain: Interceptor.Chain): Response { | ||||
|         val response = chain.proceed(chain.request()) | ||||
| 
 | ||||
|         if (!response.isSuccessful && response.code() == 403) { | ||||
|             response.close() | ||||
|             throw Exception(BLOCK_MESSAGE) | ||||
|         } | ||||
| 
 | ||||
|         return response | ||||
|     } | ||||
| 
 | ||||
|     private fun Call.asObservableIgnoreCode(code: Int): Observable<Response> { | ||||
| @ -246,6 +248,8 @@ class MangaHost : ParsedHttpSource() { | ||||
|         private val IMAGE_REGEX = "_(small|medium|xmedium)\\.".toRegex() | ||||
|         private val CDN_REGEX = "/mangas_files/.*\\.jpg".toRegex() | ||||
| 
 | ||||
|         private const val BLOCK_MESSAGE = "O site está bloqueando o Tachiyomi. Migre para outra fonte caso o problema persistir." | ||||
| 
 | ||||
|         private val DATE_FORMAT by lazy { | ||||
|             SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH) | ||||
|         } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Alessandro Jean
						Alessandro Jean