mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34: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.asCoroutineDispatcher
|
||||||
import kotlinx.coroutines.currentCoroutineContext
|
import kotlinx.coroutines.currentCoroutineContext
|
||||||
import kotlinx.coroutines.ensureActive
|
import kotlinx.coroutines.ensureActive
|
||||||
import kotlinx.coroutines.flow.buffer
|
|
||||||
import kotlinx.coroutines.flow.collect
|
import kotlinx.coroutines.flow.collect
|
||||||
import kotlinx.coroutines.flow.flow
|
import kotlinx.coroutines.flow.flow
|
||||||
import kotlinx.coroutines.flow.onCompletion
|
import kotlinx.coroutines.flow.onCompletion
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import kotlinx.coroutines.flow.onStart
|
import kotlinx.coroutines.flow.onStart
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withTimeout
|
||||||
import org.mozilla.javascript.WrappedException
|
import org.mozilla.javascript.WrappedException
|
||||||
import splitties.init.appCtx
|
import splitties.init.appCtx
|
||||||
import splitties.systemservices.notificationManager
|
import splitties.systemservices.notificationManager
|
||||||
@ -132,6 +132,25 @@ class CheckSourceService : BaseService() {
|
|||||||
|
|
||||||
private suspend fun checkSource(source: BookSource) {
|
private suspend fun checkSource(source: BookSource) {
|
||||||
kotlin.runCatching {
|
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)
|
Debug.startChecking(source)
|
||||||
source.removeInvalidGroups()
|
source.removeInvalidGroups()
|
||||||
source.removeErrorComment()
|
source.removeErrorComment()
|
||||||
@ -173,19 +192,6 @@ class CheckSourceService : BaseService() {
|
|||||||
if (finalCheckMessage.isNotBlank()) {
|
if (finalCheckMessage.isNotBlank()) {
|
||||||
throw NoStackTraceException(finalCheckMessage)
|
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