From 65c74aa8a92ecb1ba6784076fcca4c86747ad5ae Mon Sep 17 00:00:00 2001 From: seew3l <90949336+seew3l@users.noreply.github.com> Date: Sat, 18 Feb 2023 10:31:32 -0500 Subject: [PATCH] ReaderFront: Fix crash when reading a chapter (#15366) * Fix crash when open a chapter * Apply requested changes * I forgot to import json.put --- .../multisrc/readerfront/ReaderFront.kt | 38 +++++++++++++++---- .../multisrc/readerfront/ReaderFrontAPI.kt | 6 +-- .../readerfront/ReaderFrontGenerator.kt | 2 +- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/readerfront/ReaderFront.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/readerfront/ReaderFront.kt index 08c37f4a4..7e3ab39b4 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/readerfront/ReaderFront.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/readerfront/ReaderFront.kt @@ -8,12 +8,16 @@ import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.HttpSource +import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.buildJsonObject import kotlinx.serialization.json.decodeFromJsonElement import kotlinx.serialization.json.jsonArray import kotlinx.serialization.json.jsonObject import kotlinx.serialization.json.jsonPrimitive +import kotlinx.serialization.json.put +import okhttp3.Request import okhttp3.Response import uy.kohesive.injekt.injectLazy @@ -42,10 +46,13 @@ abstract class ReaderFront( GET("$apiUrl?query=${work(i18n.id, manga.url)}", headers) 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) = - GET("$apiUrl?query=${chapterById(chapter.url.toInt())}", headers) + override fun pageListRequest(chapter: SChapter): Request { + 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) = response.parse>("works").map { @@ -88,15 +95,24 @@ abstract class ReaderFront( } } - override fun chapterListParse(response: Response) = - response.parse>("chaptersByWork").map { + override fun chapterListParse(response: Response): List { + val stub = response.request.url.fragment ?: "" + return response.parse>("chaptersByWork").map { 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() chapter_number = it.number date_upload = it.timestamp } } + } override fun pageListParse(response: Response) = response.parse("chapterById").let { @@ -107,8 +123,14 @@ abstract class ReaderFront( override fun getMangaUrl(manga: SManga) = "$baseUrl/work/$lang/${manga.url}" - override fun getChapterUrl(chapter: SChapter) = - throw UnsupportedOperationException("Not implemented!") + override fun getChapterUrl(chapter: SChapter): String { + 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) = client.newCall(popularMangaRequest(page)).asObservableSuccess().map { res -> diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/readerfront/ReaderFrontAPI.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/readerfront/ReaderFrontAPI.kt index be1dc34ed..703d2509d 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/readerfront/ReaderFrontAPI.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/readerfront/ReaderFrontAPI.kt @@ -32,9 +32,9 @@ data class Work( @Serializable data class Release( val id: Int, - private val chapter: Int, - private val subchapter: Int, - private val volume: Int, + val chapter: Int, + val subchapter: Int, + val volume: Int, private val name: String, private val releaseDate: String, ) { diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/readerfront/ReaderFrontGenerator.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/readerfront/ReaderFrontGenerator.kt index 6673ecbde..53d804463 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/readerfront/ReaderFrontGenerator.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/readerfront/ReaderFrontGenerator.kt @@ -9,7 +9,7 @@ class ReaderFrontGenerator : ThemeSourceGenerator { override val themeClass = "ReaderFront" - override val baseVersionCode = 7 + override val baseVersionCode = 8 override val sources = listOf( MultiLang("Ravens Scans", "https://ravens-scans.com", listOf("es", "en"), true),