ReaderFront: Fix crash when reading a chapter (#15366)
* Fix crash when open a chapter * Apply requested changes * I forgot to import json.put
This commit is contained in:
parent
d72a9eedf4
commit
65c74aa8a9
|
@ -8,12 +8,16 @@ import eu.kanade.tachiyomi.source.model.Page
|
||||||
import eu.kanade.tachiyomi.source.model.SChapter
|
import eu.kanade.tachiyomi.source.model.SChapter
|
||||||
import eu.kanade.tachiyomi.source.model.SManga
|
import eu.kanade.tachiyomi.source.model.SManga
|
||||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||||
|
import kotlinx.serialization.encodeToString
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import kotlinx.serialization.json.JsonElement
|
import kotlinx.serialization.json.JsonElement
|
||||||
|
import kotlinx.serialization.json.buildJsonObject
|
||||||
import kotlinx.serialization.json.decodeFromJsonElement
|
import kotlinx.serialization.json.decodeFromJsonElement
|
||||||
import kotlinx.serialization.json.jsonArray
|
import kotlinx.serialization.json.jsonArray
|
||||||
import kotlinx.serialization.json.jsonObject
|
import kotlinx.serialization.json.jsonObject
|
||||||
import kotlinx.serialization.json.jsonPrimitive
|
import kotlinx.serialization.json.jsonPrimitive
|
||||||
|
import kotlinx.serialization.json.put
|
||||||
|
import okhttp3.Request
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
|
||||||
|
@ -42,10 +46,13 @@ abstract class ReaderFront(
|
||||||
GET("$apiUrl?query=${work(i18n.id, manga.url)}", headers)
|
GET("$apiUrl?query=${work(i18n.id, manga.url)}", headers)
|
||||||
|
|
||||||
override fun chapterListRequest(manga: SManga) =
|
override fun chapterListRequest(manga: SManga) =
|
||||||
GET("$apiUrl?query=${chaptersByWork(i18n.id, manga.url)}", headers)
|
GET("$apiUrl?query=${chaptersByWork(i18n.id, manga.url)}#${manga.url}", headers)
|
||||||
|
|
||||||
override fun pageListRequest(chapter: SChapter) =
|
override fun pageListRequest(chapter: SChapter): Request {
|
||||||
GET("$apiUrl?query=${chapterById(chapter.url.toInt())}", headers)
|
val jsonObj = json.parseToJsonElement(chapter.url).jsonObject
|
||||||
|
val id = jsonObj["id"]!!.jsonPrimitive.content
|
||||||
|
return GET("$apiUrl?query=${chapterById(id.toInt())}", headers)
|
||||||
|
}
|
||||||
|
|
||||||
override fun latestUpdatesParse(response: Response) =
|
override fun latestUpdatesParse(response: Response) =
|
||||||
response.parse<List<Work>>("works").map {
|
response.parse<List<Work>>("works").map {
|
||||||
|
@ -88,15 +95,24 @@ abstract class ReaderFront(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun chapterListParse(response: Response) =
|
override fun chapterListParse(response: Response): List<SChapter> {
|
||||||
response.parse<List<Release>>("chaptersByWork").map {
|
val stub = response.request.url.fragment ?: ""
|
||||||
|
return response.parse<List<Release>>("chaptersByWork").map {
|
||||||
SChapter.create().apply {
|
SChapter.create().apply {
|
||||||
url = it.id.toString()
|
val jsonObject = buildJsonObject {
|
||||||
|
put("id", it.id)
|
||||||
|
put("stub", stub)
|
||||||
|
put("volume", it.volume)
|
||||||
|
put("chapter", it.chapter)
|
||||||
|
put("subchapter", it.subchapter)
|
||||||
|
}
|
||||||
|
url = json.encodeToString(jsonObject)
|
||||||
name = it.toString()
|
name = it.toString()
|
||||||
chapter_number = it.number
|
chapter_number = it.number
|
||||||
date_upload = it.timestamp
|
date_upload = it.timestamp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun pageListParse(response: Response) =
|
override fun pageListParse(response: Response) =
|
||||||
response.parse<Chapter>("chapterById").let {
|
response.parse<Chapter>("chapterById").let {
|
||||||
|
@ -107,8 +123,14 @@ abstract class ReaderFront(
|
||||||
|
|
||||||
override fun getMangaUrl(manga: SManga) = "$baseUrl/work/$lang/${manga.url}"
|
override fun getMangaUrl(manga: SManga) = "$baseUrl/work/$lang/${manga.url}"
|
||||||
|
|
||||||
override fun getChapterUrl(chapter: SChapter) =
|
override fun getChapterUrl(chapter: SChapter): String {
|
||||||
throw UnsupportedOperationException("Not implemented!")
|
val jsonObj = json.parseToJsonElement(chapter.url).jsonObject
|
||||||
|
val stub = jsonObj["stub"]!!.jsonPrimitive.content
|
||||||
|
val volume = jsonObj["volume"]!!.jsonPrimitive.content
|
||||||
|
val chpter = jsonObj["chapter"]!!.jsonPrimitive.content
|
||||||
|
val subChpter = jsonObj["subchapter"]!!.jsonPrimitive.content
|
||||||
|
return "$baseUrl/read/$stub/$lang/$volume/$chpter.$subChpter"
|
||||||
|
}
|
||||||
|
|
||||||
override fun fetchSearchManga(page: Int, query: String, filters: FilterList) =
|
override fun fetchSearchManga(page: Int, query: String, filters: FilterList) =
|
||||||
client.newCall(popularMangaRequest(page)).asObservableSuccess().map { res ->
|
client.newCall(popularMangaRequest(page)).asObservableSuccess().map { res ->
|
||||||
|
|
|
@ -32,9 +32,9 @@ data class Work(
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Release(
|
data class Release(
|
||||||
val id: Int,
|
val id: Int,
|
||||||
private val chapter: Int,
|
val chapter: Int,
|
||||||
private val subchapter: Int,
|
val subchapter: Int,
|
||||||
private val volume: Int,
|
val volume: Int,
|
||||||
private val name: String,
|
private val name: String,
|
||||||
private val releaseDate: String,
|
private val releaseDate: String,
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -9,7 +9,7 @@ class ReaderFrontGenerator : ThemeSourceGenerator {
|
||||||
|
|
||||||
override val themeClass = "ReaderFront"
|
override val themeClass = "ReaderFront"
|
||||||
|
|
||||||
override val baseVersionCode = 7
|
override val baseVersionCode = 8
|
||||||
|
|
||||||
override val sources = listOf(
|
override val sources = listOf(
|
||||||
MultiLang("Ravens Scans", "https://ravens-scans.com", listOf("es", "en"), true),
|
MultiLang("Ravens Scans", "https://ravens-scans.com", listOf("es", "en"), true),
|
||||||
|
|
Loading…
Reference in New Issue