CuuTruyen: General improvements (#14869)

* CuuTruyen: General improvements

* switch to app's json instance
This commit is contained in:
beerpsi 2023-01-11 02:05:49 +07:00 committed by GitHub
parent 6cbee38a9a
commit 5aa52e1059
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 60 additions and 38 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'Cứu Truyện'
pkgNameSuffix = 'vi.cuutruyen'
extClass = '.CuuTruyen'
extVersionCode = 1
extVersionCode = 2
}
apply from: "$rootDir/common.gradle"

View File

@ -20,13 +20,13 @@ import eu.kanade.tachiyomi.source.online.HttpSource
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import okhttp3.CacheControl
import okhttp3.Headers
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.Request
import okhttp3.Response
import rx.Observable
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
class CuuTruyen : HttpSource(), ConfigurableSource {
@ -43,8 +43,9 @@ class CuuTruyen : HttpSource(), ConfigurableSource {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}
override fun headersBuilder() = Headers.Builder()
.add("Referer", "$baseUrl/")
private val json: Json by injectLazy()
override fun headersBuilder() = super.headersBuilder().add("Referer", "$baseUrl/")
override val client = network.client.newBuilder()
.rateLimit(3)
@ -94,12 +95,16 @@ class CuuTruyen : HttpSource(), ConfigurableSource {
if (id.toIntOrNull() == null) {
throw Exception("ID tìm kiếm không hợp lệ (phải là một số).")
}
val url = "/mangas/$id"
fetchMangaDetails(
SManga.create().apply {
url = "/mangas/$id"
this.url = url
}
)
.map { MangasPage(listOf(it), false) }
.map {
it.url = url
MangasPage(listOf(it), false)
}
}
else -> super.fetchSearchManga(page, query, filters)
}
@ -153,11 +158,7 @@ class CuuTruyen : HttpSource(), ConfigurableSource {
return chapterDto.data.pages!!.map { it.toPage() }
}
override fun imageUrlParse(response: Response): String = throw Exception("Not used")
private val json = Json {
ignoreUnknownKeys = true
}
override fun imageUrlParse(response: Response): String = throw UnsupportedOperationException("Not used")
private inline fun <reified T> Response.parseAs(): T = use {
json.decodeFromString(body?.string().orEmpty())

View File

@ -20,7 +20,7 @@ class CuuTruyenUrlActivity : Activity() {
startActivity(
Intent().apply {
action = "eu.kanade.tachiyomi.SEARCH"
putExtra("query", "id:$id")
putExtra("query", "${CuuTruyen.PREFIX_ID_SEARCH}$id")
putExtra("filter", packageName)
}
)

View File

@ -55,6 +55,6 @@ data class PageDto(
val url = imageUrl.toHttpUrl().newBuilder().apply {
addQueryParameter(CuuTruyenImageInterceptor.KEY, dto.drmData)
}.build().toString()
return Page(dto.order, "", url)
return Page(dto.order, imageUrl = url)
}
}

View File

@ -39,9 +39,7 @@ data class MangaDto(
if (dto.team != null) {
description += "Nhóm dịch: ${dto.team.name}\n\n"
}
if (dto.description != null) {
description += dto.description
}
description += dto.description ?: ""
thumbnail_url = dto.coverUrl
if (coverQuality == "cover_url") {