This commit is contained in:
Horis
2025-05-10 11:05:00 +08:00
parent f502d2cec4
commit 2d4805007f
5 changed files with 20 additions and 3 deletions
@@ -16,6 +16,7 @@ import io.legado.app.utils.findNSPrefix
import io.legado.app.utils.printOnDebug
import io.legado.app.utils.toRequestBody
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.withContext
import okhttp3.Interceptor
import okhttp3.MediaType.Companion.toMediaType
@@ -35,6 +36,7 @@ import java.time.LocalDateTime
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter
import java.util.concurrent.TimeUnit
import kotlin.coroutines.coroutineContext
@Suppress("unused", "MemberVisibilityCanBePrivate")
open class WebDav(
@@ -245,6 +247,8 @@ open class WebDav(
val requestBody = EXISTS.toRequestBody("application/xml".toMediaType())
method("PROPFIND", requestBody)
}.use { it.isSuccessful }
}.onFailure {
coroutineContext.ensureActive()
}.getOrDefault(false)
}
@@ -259,6 +263,8 @@ open class WebDav(
val requestBody = EXISTS.toRequestBody("application/xml".toMediaType())
method("PROPFIND", requestBody)
}.use { it.code != 401 }
}.onFailure {
coroutineContext.ensureActive()
}.getOrDefault(true)
}
@@ -279,6 +285,7 @@ open class WebDav(
}
}
}.onFailure {
coroutineContext.ensureActive()
AppLog.put("WebDav创建目录失败\n${it.localizedMessage}", it)
}.isSuccess
}
@@ -335,6 +342,7 @@ open class WebDav(
}
}
}.onFailure {
coroutineContext.ensureActive()
AppLog.put("WebDav上传失败\n${it.localizedMessage}", it)
throw WebDavException("WebDav上传失败\n${it.localizedMessage}")
}
@@ -355,6 +363,7 @@ open class WebDav(
}
}
}.onFailure {
coroutineContext.ensureActive()
AppLog.put("WebDav上传失败\n${it.localizedMessage}", it)
throw WebDavException("WebDav上传失败\n${it.localizedMessage}")
}
@@ -375,6 +384,7 @@ open class WebDav(
}
}
}.onFailure {
coroutineContext.ensureActive()
AppLog.put("WebDav上传失败\n${it.localizedMessage}", it)
throw WebDavException("WebDav上传失败\n${it.localizedMessage}")
}
@@ -405,6 +415,7 @@ open class WebDav(
checkResult(it)
}
}.onFailure {
coroutineContext.ensureActive()
AppLog.put("WebDav删除失败\n${it.localizedMessage}", it)
}.isSuccess
}
@@ -200,6 +200,7 @@ object ReadBook : CoroutineScope by MainScope() {
) {
durChapterIndex = progress.durChapterIndex
durChapterPos = progress.durChapterPos
saveRead()
clearTextChapter()
callBack?.upContent()
loadContent(resetPageOffset = true)
@@ -217,6 +217,7 @@ object WebBook {
.evalJS(preUpdateJs)
}
}.onFailure {
coroutineContext.ensureActive()
AppLog.put("执行preUpdateJs规则失败 书源:${bookSource.bookSourceName}", it)
}
}
@@ -264,6 +265,8 @@ object WebBook {
body = res.body
)
}
}.onFailure {
coroutineContext.ensureActive()
}
}
@@ -391,6 +394,8 @@ object WebBook {
return@runCatching searchBook.toBook()
}
throw NoStackTraceException("未搜索到 $name($author) 书籍")
}.onFailure {
coroutineContext.ensureActive()
}
}
@@ -22,6 +22,7 @@ import io.legado.app.utils.stackTraceStr
import io.legado.app.utils.toastOnUi
import io.legado.app.utils.writeToOutputStream
import kotlinx.coroutines.delay
import kotlinx.coroutines.ensureActive
import java.io.File
@@ -92,8 +93,8 @@ class BookshelfManageViewModel(application: Application) : BaseViewModel(applica
AppLog.put("搜索书籍出错\n${it.localizedMessage}", it, true)
}.getOrNull() ?: return@forEachIndexed
kotlin.runCatching {
if (book.tocUrl.isEmpty()) {
WebBook.getBookInfoAwait(source, book)
if (newBook.tocUrl.isEmpty()) {
WebBook.getBookInfoAwait(source, newBook)
}
}.onFailure {
AppLog.put("获取书籍详情出错\n${it.localizedMessage}", it, true)
@@ -1557,7 +1557,6 @@ class ReadBookActivity : BaseReadBookActivity(),
setMessage(R.string.cloud_progress_exceeds_current)
okButton {
ReadBook.setProgress(progress)
ReadBook.saveRead()
}
noButton()
}