Add more replacement suspend functions for source APIs
These are basically 1-to-1 replacements for the existing RxJava APIs. This will make the initial migration off of RxJava simpler. We'll revisit the actual call flows in followup versions of the API. (cherry picked from commit 26c5d761da4ba577481f41e63f03952b8a6c323f) # Conflicts: # data/src/main/java/tachiyomi/data/source/SourcePagingSource.kt # source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/online/HttpSource.kt # source-api/src/commonMain/kotlin/eu/kanade/tachiyomi/source/online/HttpSourceFetcher.kt
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package exh.md.handlers
|
||||
|
||||
import eu.kanade.tachiyomi.network.POST
|
||||
import eu.kanade.tachiyomi.network.asObservableSuccess
|
||||
import eu.kanade.tachiyomi.network.awaitSuccess
|
||||
import eu.kanade.tachiyomi.network.interceptor.rateLimit
|
||||
import eu.kanade.tachiyomi.network.parseAs
|
||||
@@ -22,6 +21,7 @@ import okhttp3.Request
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import okhttp3.Response
|
||||
import rx.Observable
|
||||
import tachiyomi.core.util.lang.runAsObservable
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
@@ -154,12 +154,13 @@ class BilibiliHandler(currentClient: OkHttpClient) {
|
||||
.mapIndexed { i, page -> Page(i, page.path, "") }
|
||||
}
|
||||
|
||||
suspend fun getImageUrl(page: Page): String {
|
||||
val response = client.newCall(imageUrlRequest(page)).awaitSuccess()
|
||||
return imageUrlParse(response)
|
||||
}
|
||||
|
||||
fun fetchImageUrl(page: Page): Observable<String> {
|
||||
return client.newCall(imageUrlRequest(page))
|
||||
.asObservableSuccess()
|
||||
.map {
|
||||
imageUrlParse(it)
|
||||
}
|
||||
return runAsObservable { getImageUrl(page) }
|
||||
}
|
||||
|
||||
private fun imageUrlRequest(page: Page): Request {
|
||||
|
||||
@@ -134,4 +134,13 @@ class PageHandler(
|
||||
else -> superMethod(page)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getImageUrl(page: Page, superMethod: suspend (Page) -> String): String {
|
||||
return when {
|
||||
page.url.contains("/bfs/comic/") -> {
|
||||
bilibiliHandler.getImageUrl(page)
|
||||
}
|
||||
else -> superMethod(page)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import eu.kanade.tachiyomi.source.Source
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import okhttp3.Response
|
||||
import rx.Observable
|
||||
import tachiyomi.core.preference.Preference
|
||||
|
||||
interface DataSaver {
|
||||
@@ -22,15 +21,6 @@ interface DataSaver {
|
||||
}
|
||||
}
|
||||
|
||||
fun HttpSource.fetchImage(page: Page, dataSaver: DataSaver): Observable<Response> {
|
||||
val imageUrl = page.imageUrl ?: return fetchImage(page)
|
||||
page.imageUrl = dataSaver.compress(imageUrl)
|
||||
return fetchImage(page)
|
||||
.doOnNext {
|
||||
page.imageUrl = imageUrl
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun HttpSource.getImage(page: Page, dataSaver: DataSaver): Response {
|
||||
val imageUrl = page.imageUrl ?: return getImage(page)
|
||||
page.imageUrl = dataSaver.compress(imageUrl)
|
||||
|
||||
@@ -35,3 +35,29 @@ fun UrlImportableSource.urlImportFetchSearchManga(context: Context, query: Strin
|
||||
}
|
||||
else -> fail()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A version of fetchSearchManga that supports URL importing
|
||||
*/
|
||||
suspend fun UrlImportableSource.urlImportFetchSearchMangaSuspend(context: Context, query: String, fail: suspend () -> MangasPage): MangasPage =
|
||||
when {
|
||||
query.startsWith("http://") || query.startsWith("https://") -> {
|
||||
val res = galleryAdder.addGallery(
|
||||
context = context,
|
||||
url = query,
|
||||
fav = false,
|
||||
forceSource = this
|
||||
)
|
||||
|
||||
MangasPage(
|
||||
if (res is GalleryAddEvent.Success) {
|
||||
listOf(res.manga.toSManga())
|
||||
} else {
|
||||
emptyList()
|
||||
},
|
||||
false,
|
||||
)
|
||||
}
|
||||
else -> fail()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user