[YuriNeko] Fix error interceptor and URL intent filter (#14996)

* fix: return original response if cannot parse as ErrorResponseDto

* fix: make YuriNekoUrlActivity not die from lack of kotlin

* fix: add trailing slash to referer

* accept suggestion

Co-authored-by: stevenyomi <95685115+stevenyomi@users.noreply.github.com>

Co-authored-by: stevenyomi <95685115+stevenyomi@users.noreply.github.com>
This commit is contained in:
beerpsi 2023-01-17 18:36:23 +07:00 committed by GitHub
parent 04f8307fd9
commit 326ddc2ad7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 32 deletions

View File

@ -12,10 +12,15 @@
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="yurineko.net"
android:pathPattern="/..*"
<data android:host="yurineko.net"
android:scheme="https" />
<data android:pathPattern="/manga/..*" />
<data android:pathPattern="/origin/..*" />
<data android:pathPattern="/author/..*" />
<data android:pathPattern="/tag/..*" />
<data android:pathPattern="/couple/..*" />
<data android:pathPattern="/team/..*" />
</intent-filter>
</activity>
</application>

View File

@ -6,7 +6,7 @@ ext {
extName = 'YuriNeko'
pkgNameSuffix = 'vi.yurineko'
extClass = '.YuriNeko'
extVersionCode = 2
extVersionCode = 3
isNsfw = true
}

View File

@ -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<ErrorResponseDto>()
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<ErrorResponseDto>()
} 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 {

View File

@ -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)
}
)