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.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<List<Work>>("works").map {
 | 
			
		||||
@ -88,15 +95,24 @@ abstract class ReaderFront(
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    override fun chapterListParse(response: Response) =
 | 
			
		||||
        response.parse<List<Release>>("chaptersByWork").map {
 | 
			
		||||
    override fun chapterListParse(response: Response): List<SChapter> {
 | 
			
		||||
        val stub = response.request.url.fragment ?: ""
 | 
			
		||||
        return response.parse<List<Release>>("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<Chapter>("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 ->
 | 
			
		||||
 | 
			
		||||
@ -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,
 | 
			
		||||
) {
 | 
			
		||||
 | 
			
		||||
@ -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),
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user