[修复] 某些情况下,发现没有数据的问题

This commit is contained in:
HapeLee committed 2025-11-29 14:55:44 +08:00
1 parent 573cc15817
commit 3720847ebb
1 file changed
+6 -1
@@ -5,8 +5,10 @@ import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchBook
import io.legado.app.help.book.isNotShelf import io.legado.app.help.book.isNotShelf
import io.legado.app.model.webBook.WebBook import io.legado.app.model.webBook.WebBook
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
import kotlinx.coroutines.withContext
interface ExploreRepository { interface ExploreRepository {
fun getBookshelfItems(): Flow<List<SearchBook>> fun getBookshelfItems(): Flow<List<SearchBook>>
@@ -31,13 +33,16 @@ class ExploreRepositoryImpl(
} }
override suspend fun exploreBook(source: BookSource, url: String, page: Int): Result<List<SearchBook>> { override suspend fun exploreBook(source: BookSource, url: String, page: Int): Result<List<SearchBook>> {
return try { return withContext(Dispatchers.IO) {
try {
val books = WebBook.exploreBookSuspend(source, url, page) val books = WebBook.exploreBookSuspend(source, url, page)
Result.success(books) Result.success(books)
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace()
Result.failure(e) Result.failure(e)
} }
} }
}
override suspend fun saveSearchBooks(books: List<SearchBook>) { override suspend fun saveSearchBooks(books: List<SearchBook>) {
appDb.searchBookDao.insert(*books.toTypedArray()) appDb.searchBookDao.insert(*books.toTypedArray())