Fix page reporting
This commit is contained in:
parent
183da5cc84
commit
90654dc027
@ -160,7 +160,7 @@ class MangaDex(delegate: HttpSource, val context: Context) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun fetchPageList(chapter: SChapter): Observable<List<Page>> {
|
override fun fetchPageList(chapter: SChapter): Observable<List<Page>> {
|
||||||
return runAsObservable({ pageHandler.fetchPageList(chapter, isLogged(), usePort443Only(), dataSaver()) })
|
return runAsObservable({ pageHandler.fetchPageList(chapter, isLogged(), usePort443Only(), dataSaver(), delegate) })
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fetchImage(page: Page): Observable<Response> {
|
override fun fetchImage(page: Page): Observable<Response> {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package exh.md.handlers
|
package exh.md.handlers
|
||||||
|
|
||||||
import eu.kanade.tachiyomi.network.GET
|
import eu.kanade.tachiyomi.network.GET
|
||||||
|
import eu.kanade.tachiyomi.network.await
|
||||||
import eu.kanade.tachiyomi.source.model.Page
|
import eu.kanade.tachiyomi.source.model.Page
|
||||||
import exh.md.dto.MangaPlusSerializer
|
import exh.md.dto.MangaPlusSerializer
|
||||||
import kotlinx.serialization.protobuf.ProtoBuf
|
import kotlinx.serialization.protobuf.ProtoBuf
|
||||||
@ -25,8 +26,8 @@ class MangaPlusHandler(currentClient: OkHttpClient) {
|
|||||||
.addInterceptor { imageIntercept(it) }
|
.addInterceptor { imageIntercept(it) }
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
fun fetchPageList(chapterId: String): List<Page> {
|
suspend fun fetchPageList(chapterId: String): List<Page> {
|
||||||
val response = client.newCall(pageListRequest(chapterId)).execute()
|
val response = client.newCall(pageListRequest(chapterId)).await()
|
||||||
return pageListParse(response)
|
return pageListParse(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,8 +8,12 @@ import eu.kanade.tachiyomi.util.lang.withIOContext
|
|||||||
import exh.md.dto.AtHomeDto
|
import exh.md.dto.AtHomeDto
|
||||||
import exh.md.dto.ChapterDto
|
import exh.md.dto.ChapterDto
|
||||||
import exh.md.service.MangaDexService
|
import exh.md.service.MangaDexService
|
||||||
|
import exh.md.utils.MdApi
|
||||||
import exh.md.utils.MdUtil
|
import exh.md.utils.MdUtil
|
||||||
import okhttp3.Headers
|
import okhttp3.Headers
|
||||||
|
import tachiyomi.source.Source
|
||||||
|
import kotlin.reflect.full.superclasses
|
||||||
|
import kotlin.reflect.jvm.isAccessible
|
||||||
|
|
||||||
class PageHandler(
|
class PageHandler(
|
||||||
private val headers: Headers,
|
private val headers: Headers,
|
||||||
@ -19,7 +23,7 @@ class PageHandler(
|
|||||||
private val mdList: MdList,
|
private val mdList: MdList,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
suspend fun fetchPageList(chapter: SChapter, isLogged: Boolean, usePort443Only: Boolean, dataSaver: Boolean): List<Page> {
|
suspend fun fetchPageList(chapter: SChapter, isLogged: Boolean, usePort443Only: Boolean, dataSaver: Boolean, mangadex: Source): List<Page> {
|
||||||
return withIOContext {
|
return withIOContext {
|
||||||
val chapterResponse = service.viewChapter(MdUtil.getChapterId(chapter.url))
|
val chapterResponse = service.viewChapter(MdUtil.getChapterId(chapter.url))
|
||||||
|
|
||||||
@ -36,13 +40,35 @@ class PageHandler(
|
|||||||
headers
|
headers
|
||||||
}
|
}
|
||||||
|
|
||||||
val (atHomeRequestUrl, atHomeResponse) = service.getAtHomeServer(headers, MdUtil.getChapterId(chapter.url), usePort443Only)
|
val atHomeRequestUrl = if (usePort443Only) {
|
||||||
|
"${MdApi.atHomeServer}/${MdUtil.getChapterId(chapter.url)}?forcePort443=true"
|
||||||
|
} else {
|
||||||
|
"${MdApi.atHomeServer}/${MdUtil.getChapterId(chapter.url)}"
|
||||||
|
}
|
||||||
|
|
||||||
|
updateExtensionVariable(mangadex, atHomeRequestUrl)
|
||||||
|
|
||||||
|
val atHomeResponse = service.getAtHomeServer(atHomeRequestUrl, headers)
|
||||||
|
|
||||||
pageListParse(chapterResponse, atHomeRequestUrl, atHomeResponse, dataSaver)
|
pageListParse(chapterResponse, atHomeRequestUrl, atHomeResponse, dataSaver)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
fun updateExtensionVariable(mangadex: Source, atHomeRequestUrl: String) {
|
||||||
|
val mangadexSuperclass = mangadex::class.superclasses.first()
|
||||||
|
|
||||||
|
val helperCallable = mangadexSuperclass.members.find { it.name == "helper" } ?: return
|
||||||
|
helperCallable.isAccessible = true
|
||||||
|
val helper = helperCallable.call(mangadex) ?: return
|
||||||
|
|
||||||
|
val tokenTrackerCallable = helper::class.members.find { it.name == "tokenTracker" } ?: return
|
||||||
|
tokenTrackerCallable.isAccessible = true
|
||||||
|
val tokenTracker = tokenTrackerCallable.call(helper) as? HashMap<String, Long> ?: return
|
||||||
|
tokenTracker[atHomeRequestUrl] = System.currentTimeMillis()
|
||||||
|
}
|
||||||
|
|
||||||
fun pageListParse(
|
fun pageListParse(
|
||||||
chapterDto: ChapterDto,
|
chapterDto: ChapterDto,
|
||||||
atHomeRequestUrl: String,
|
atHomeRequestUrl: String,
|
||||||
@ -57,10 +83,8 @@ class PageHandler(
|
|||||||
}
|
}
|
||||||
val now = System.currentTimeMillis()
|
val now = System.currentTimeMillis()
|
||||||
|
|
||||||
val pages = pageArray.mapIndexed { pos, imgUrl ->
|
return pageArray.mapIndexed { pos, imgUrl ->
|
||||||
Page(pos + 1, "${atHomeDto.baseUrl},$atHomeRequestUrl,$now", imgUrl)
|
Page(pos, "${atHomeDto.baseUrl},$atHomeRequestUrl,$now", imgUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
return pages
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,13 +95,11 @@ class MangaDexService(
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getAtHomeServer(
|
suspend fun getAtHomeServer(
|
||||||
headers: Headers,
|
atHomeRequestUrl: String,
|
||||||
chapterId: String,
|
headers: Headers
|
||||||
forcePort443: Boolean,
|
): AtHomeDto {
|
||||||
): Pair<String, AtHomeDto> {
|
return client.newCall(GET(atHomeRequestUrl, headers, CacheControl.FORCE_NETWORK))
|
||||||
val url = "${MdApi.atHomeServer}/$chapterId?forcePort443=$forcePort443"
|
|
||||||
return client.newCall(GET(url, headers, CacheControl.FORCE_NETWORK))
|
|
||||||
.await()
|
.await()
|
||||||
.let { it.request.url.toUrl().toString() to it.parseAs(MdUtil.jsonParser) }
|
.parseAs()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user