[MangaLib] Check page response size

pull/250/head
Koitharu 3 years ago
parent 4d22e7d1e8
commit 2f7e704e21
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

@ -2,6 +2,8 @@ package org.koitharu.kotatsu.parsers.site.ru.rulib
import androidx.collection.ArraySet import androidx.collection.ArraySet
import kotlinx.coroutines.withTimeoutOrNull import kotlinx.coroutines.withTimeoutOrNull
import okhttp3.Response
import okhttp3.internal.headersContentLength
import org.json.JSONArray import org.json.JSONArray
import org.json.JSONObject import org.json.JSONObject
import org.jsoup.nodes.Document import org.jsoup.nodes.Document
@ -30,7 +32,7 @@ internal open class MangaLibParser(
override val configKeyDomain = ConfigKey.Domain("mangalib.me") override val configKeyDomain = ConfigKey.Domain("mangalib.me")
override val authUrl: String override val authUrl: String
get() = "https://${domain}/login" get() = "https://$domain/login"
override val sortOrders: Set<SortOrder> = EnumSet.of( override val sortOrders: Set<SortOrder> = EnumSet.of(
SortOrder.RATING, SortOrder.RATING,
@ -163,7 +165,9 @@ internal open class MangaLibParser(
key = href.substringAfterLast('='), key = href.substringAfterLast('='),
source = source, source = source,
) )
} else null } else {
null
}
} ?: manga.tags, } ?: manga.tags,
isNsfw = isNsfw(doc), isNsfw = isNsfw(doc),
description = info?.selectFirst("div.media-description__text")?.html(), description = info?.selectFirst("div.media-description__text")?.html(),
@ -226,7 +230,7 @@ internal open class MangaLibParser(
} }
override suspend fun getTags(): Set<MangaTag> { override suspend fun getTags(): Set<MangaTag> {
val url = "https://${domain}/manga-list" val url = "https://$domain/manga-list"
val doc = webClient.httpGet(url).parseHtml() val doc = webClient.httpGet(url).parseHtml()
val scripts = doc.body().select("script") val scripts = doc.body().select("script")
for (script in scripts) { for (script in scripts) {
@ -266,7 +270,7 @@ internal open class MangaLibParser(
private suspend fun tryHeadImage(url: String): Boolean = runCatchingCancellable { private suspend fun tryHeadImage(url: String): Boolean = runCatchingCancellable {
withTimeoutOrNull(3_000) { withTimeoutOrNull(3_000) {
webClient.httpHead(url).use { response -> webClient.httpHead(url).use { response ->
response.isSuccessful && response.mimeType?.startsWith("image/") == true response.isValidImage()
} }
} ?: false } ?: false
}.getOrDefault(false) }.getOrDefault(false)
@ -335,6 +339,10 @@ internal open class MangaLibParser(
return result return result
} }
private fun Response.isValidImage(): Boolean {
return isSuccessful && mimeType?.startsWith("image/") == true && headersContentLength() >= 1024L
}
@MangaSourceParser("MANGALIB", "MangaLib", "ru") @MangaSourceParser("MANGALIB", "MangaLib", "ru")
class Impl(context: MangaLoaderContext) : MangaLibParser(context, MangaSource.MANGALIB) class Impl(context: MangaLoaderContext) : MangaLibParser(context, MangaSource.MANGALIB)

Loading…
Cancel
Save