mirror of
https://github.com/gedoor/legado.git
synced 2024-07-19 01:17:25 +08:00
优化
This commit is contained in:
parent
df7d911552
commit
5182f68bd7
@ -34,13 +34,13 @@ import kotlinx.coroutines.TimeoutCancellationException
|
||||
import kotlinx.coroutines.asCoroutineDispatcher
|
||||
import kotlinx.coroutines.currentCoroutineContext
|
||||
import kotlinx.coroutines.ensureActive
|
||||
import kotlinx.coroutines.flow.buffer
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.onCompletion
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withTimeout
|
||||
import org.mozilla.javascript.WrappedException
|
||||
import splitties.init.appCtx
|
||||
import splitties.systemservices.notificationManager
|
||||
@ -132,6 +132,25 @@ class CheckSourceService : BaseService() {
|
||||
|
||||
private suspend fun checkSource(source: BookSource) {
|
||||
kotlin.runCatching {
|
||||
withTimeout(CheckSource.timeout) {
|
||||
doCheckSource(source)
|
||||
}
|
||||
}.onSuccess {
|
||||
Debug.updateFinalMessage(source.bookSourceUrl, "校验成功")
|
||||
}.onFailure {
|
||||
currentCoroutineContext().ensureActive()
|
||||
when (it) {
|
||||
is TimeoutCancellationException -> source.addGroup("校验超时")
|
||||
is ScriptException, is WrappedException -> source.addGroup("js失效")
|
||||
!is NoStackTraceException -> source.addGroup("网站失效")
|
||||
}
|
||||
source.addErrorComment(it)
|
||||
Debug.updateFinalMessage(source.bookSourceUrl, "校验失败:${it.localizedMessage}")
|
||||
}
|
||||
source.respondTime = Debug.getRespondTime(source.bookSourceUrl)
|
||||
}
|
||||
|
||||
private suspend fun doCheckSource(source: BookSource) {
|
||||
Debug.startChecking(source)
|
||||
source.removeInvalidGroups()
|
||||
source.removeErrorComment()
|
||||
@ -173,19 +192,6 @@ class CheckSourceService : BaseService() {
|
||||
if (finalCheckMessage.isNotBlank()) {
|
||||
throw NoStackTraceException(finalCheckMessage)
|
||||
}
|
||||
}.onSuccess {
|
||||
Debug.updateFinalMessage(source.bookSourceUrl, "校验成功")
|
||||
}.onFailure {
|
||||
currentCoroutineContext().ensureActive()
|
||||
when (it) {
|
||||
is TimeoutCancellationException -> source.addGroup("校验超时")
|
||||
is ScriptException, is WrappedException -> source.addGroup("js失效")
|
||||
!is NoStackTraceException -> source.addGroup("网站失效")
|
||||
}
|
||||
source.addErrorComment(it)
|
||||
Debug.updateFinalMessage(source.bookSourceUrl, "校验失败:${it.localizedMessage}")
|
||||
}
|
||||
source.respondTime = Debug.getRespondTime(source.bookSourceUrl)
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user