diff --git a/src/vi/yurineko/AndroidManifest.xml b/src/vi/yurineko/AndroidManifest.xml index 2e9289da3..2c0409d96 100644 --- a/src/vi/yurineko/AndroidManifest.xml +++ b/src/vi/yurineko/AndroidManifest.xml @@ -12,10 +12,15 @@ - + + + + + + + diff --git a/src/vi/yurineko/build.gradle b/src/vi/yurineko/build.gradle index 5144545c2..5b72d60c0 100644 --- a/src/vi/yurineko/build.gradle +++ b/src/vi/yurineko/build.gradle @@ -6,7 +6,7 @@ ext { extName = 'YuriNeko' pkgNameSuffix = 'vi.yurineko' extClass = '.YuriNeko' - extVersionCode = 2 + extVersionCode = 3 isNsfw = true } diff --git a/src/vi/yurineko/src/eu/kanade/tachiyomi/extension/vi/yurineko/YuriNeko.kt b/src/vi/yurineko/src/eu/kanade/tachiyomi/extension/vi/yurineko/YuriNeko.kt index 5a1f1b614..1d44e9afd 100644 --- a/src/vi/yurineko/src/eu/kanade/tachiyomi/extension/vi/yurineko/YuriNeko.kt +++ b/src/vi/yurineko/src/eu/kanade/tachiyomi/extension/vi/yurineko/YuriNeko.kt @@ -42,19 +42,11 @@ class YuriNeko : HttpSource() { override val client = network.cloudflareClient.newBuilder() .rateLimit(3, 1, TimeUnit.SECONDS) - .addInterceptor { authIntercept(it) } - .addInterceptor { chain -> - val response = chain.proceed(chain.request()) + .addInterceptor(::authIntercept) + .addInterceptor(::errorIntercept) + .build() - if (response.code >= 400 && response.body != null) { - val error = response.parseAs() - response.close() - throw IOException("${error.message}\nĐăng nhập qua WebView và thử lại.") - } - response - }.build() - - override fun headersBuilder() = Headers.Builder().add("Referer", baseUrl) + override fun headersBuilder() = Headers.Builder().add("Referer", "$baseUrl/") private fun authIntercept(chain: Interceptor.Chain): Response { val request = chain.request() @@ -70,6 +62,20 @@ class YuriNeko : HttpSource() { }.build() return chain.proceed(authRequest) } + private fun errorIntercept(chain: Interceptor.Chain): Response { + val response = chain.proceed(chain.request()) + + if (response.code >= 400 && response.body != null) { + val error = try { + response.parseAs() + } catch (_: Throwable) { + return response + } + response.close() + throw IOException("${error.message}\nĐăng nhập qua WebView và thử lại.") + } + return response + } override fun popularMangaRequest(page: Int): Request = GET( url = apiUrl.toHttpUrl().newBuilder().apply { diff --git a/src/vi/yurineko/src/eu/kanade/tachiyomi/extension/vi/yurineko/YuriNekoUrlActivity.kt b/src/vi/yurineko/src/eu/kanade/tachiyomi/extension/vi/yurineko/YuriNekoUrlActivity.kt index 76ecf4297..80d678255 100644 --- a/src/vi/yurineko/src/eu/kanade/tachiyomi/extension/vi/yurineko/YuriNekoUrlActivity.kt +++ b/src/vi/yurineko/src/eu/kanade/tachiyomi/extension/vi/yurineko/YuriNekoUrlActivity.kt @@ -8,29 +8,26 @@ import android.util.Log import kotlin.system.exitProcess class YuriNekoUrlActivity : Activity() { - private fun prefixDeterminer(path: String): String? = when (path) { - "manga" -> YuriNeko.PREFIX_ID_SEARCH - "origin" -> YuriNeko.PREFIX_DOUJIN_SEARCH - "author" -> YuriNeko.PREFIX_AUTHOR_SEARCH - "tag" -> YuriNeko.PREFIX_TAG_SEARCH - "couple" -> YuriNeko.PREFIX_COUPLE_SEARCH - "team" -> YuriNeko.PREFIX_TEAM_SEARCH - else -> null - } - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val pathSegments = intent?.data?.pathSegments - if (pathSegments != null && - pathSegments.size > 2 && - prefixDeterminer(pathSegments[1]) != null - ) { - val id = pathSegments[2] + if (pathSegments != null && pathSegments.size > 1) { + val id = pathSegments[1] try { startActivity( Intent().apply { action = "eu.kanade.tachiyomi.SEARCH" - putExtra("query", "${prefixDeterminer(pathSegments[1])}$id") + with(pathSegments[0]) { + when { + equals("manga") -> putExtra("query", "${YuriNeko.PREFIX_ID_SEARCH}$id") + equals("origin") -> putExtra("query", "${YuriNeko.PREFIX_DOUJIN_SEARCH}$id") + equals("author") -> putExtra("query", "${YuriNeko.PREFIX_AUTHOR_SEARCH}$id") + equals("tag") -> putExtra("query", "${YuriNeko.PREFIX_TAG_SEARCH}$id") + equals("couple") -> putExtra("query", "${YuriNeko.PREFIX_COUPLE_SEARCH}$id") + equals("team") -> putExtra("query", "${YuriNeko.PREFIX_TEAM_SEARCH}$id") + else -> putExtra("query", "${YuriNeko.PREFIX_ID_SEARCH}$id") + } + } putExtra("filter", packageName) } )