优化
This commit is contained in:
@@ -81,6 +81,7 @@ class AnalyzeUrl(
|
||||
private val ruleData: RuleDataInterface? = null,
|
||||
private val chapter: BookChapter? = null,
|
||||
private val readTimeout: Long? = null,
|
||||
private val callTimeout: Long? = null,
|
||||
private var coroutineContext: CoroutineContext = EmptyCoroutineContext,
|
||||
headerMapF: Map<String, String>? = null,
|
||||
hasLoginHeader: Boolean = true
|
||||
@@ -456,13 +457,19 @@ class AnalyzeUrl(
|
||||
|
||||
private fun getClient(): OkHttpClient {
|
||||
val client = getProxyClient(proxy)
|
||||
if (readTimeout == null) {
|
||||
if (readTimeout == null && callTimeout == null) {
|
||||
return client
|
||||
}
|
||||
return client.newBuilder()
|
||||
.readTimeout(readTimeout, TimeUnit.MILLISECONDS)
|
||||
.callTimeout(max(60 * 1000L, readTimeout * 2), TimeUnit.MILLISECONDS)
|
||||
.build()
|
||||
return client.newBuilder().run {
|
||||
if (readTimeout != null) {
|
||||
readTimeout(readTimeout, TimeUnit.MILLISECONDS)
|
||||
callTimeout(max(60 * 1000L, readTimeout * 2), TimeUnit.MILLISECONDS)
|
||||
}
|
||||
if (callTimeout != null) {
|
||||
callTimeout(callTimeout, TimeUnit.MILLISECONDS)
|
||||
}
|
||||
build()
|
||||
}
|
||||
}
|
||||
|
||||
fun getResponse(): Response {
|
||||
|
||||
@@ -59,6 +59,7 @@ import java.io.FileNotFoundException
|
||||
import java.io.FileOutputStream
|
||||
import java.io.InputStream
|
||||
import java.util.regex.Pattern
|
||||
import kotlin.coroutines.coroutineContext
|
||||
|
||||
/**
|
||||
* 书籍文件导入 目录正文解析
|
||||
@@ -208,7 +209,7 @@ object LocalBook {
|
||||
/**
|
||||
* 下载在线的文件并自动导入到阅读(txt umd epub)
|
||||
*/
|
||||
fun importFileOnLine(
|
||||
suspend fun importFileOnLine(
|
||||
str: String,
|
||||
fileName: String,
|
||||
source: BaseSource? = null,
|
||||
@@ -267,7 +268,9 @@ object LocalBook {
|
||||
): List<Book> {
|
||||
val archiveFileDoc = FileDoc.fromUri(archiveFileUri, false)
|
||||
val files = ArchiveUtils.deCompress(archiveFileDoc, filter = filter)
|
||||
if (files.isEmpty()) throw NoStackTraceException(appCtx.getString(R.string.unsupport_archivefile_entry))
|
||||
if (files.isEmpty()) {
|
||||
throw NoStackTraceException(appCtx.getString(R.string.unsupport_archivefile_entry))
|
||||
}
|
||||
return files.map {
|
||||
saveBookFile(FileInputStream(it), saveFileName ?: it.name).let { uri ->
|
||||
importFile(uri).apply {
|
||||
@@ -313,7 +316,9 @@ object LocalBook {
|
||||
errorCount += 1
|
||||
}
|
||||
}
|
||||
if (errorCount == uris.size) throw NoStackTraceException("ImportFiles Error:\nAll input files occur error")
|
||||
if (errorCount == uris.size) {
|
||||
throw NoStackTraceException("ImportFiles Error:\nAll input files occur error")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -379,7 +384,7 @@ object LocalBook {
|
||||
/**
|
||||
* 下载在线的文件
|
||||
*/
|
||||
fun saveBookFile(
|
||||
suspend fun saveBookFile(
|
||||
str: String,
|
||||
fileName: String,
|
||||
source: BaseSource? = null,
|
||||
@@ -387,7 +392,11 @@ object LocalBook {
|
||||
AppConfig.defaultBookTreeUri
|
||||
?: throw NoBooksDirException()
|
||||
val inputStream = when {
|
||||
str.isAbsUrl() -> AnalyzeUrl(str, source = source).getInputStream()
|
||||
str.isAbsUrl() -> AnalyzeUrl(
|
||||
str, source = source, callTimeout = 0,
|
||||
coroutineContext = coroutineContext
|
||||
).getInputStreamAwait()
|
||||
|
||||
str.isDataUrl() -> ByteArrayInputStream(
|
||||
Base64.decode(
|
||||
str.substringAfter("base64,"),
|
||||
|
||||
@@ -265,11 +265,8 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadWebFile(
|
||||
book: Book,
|
||||
scope: CoroutineScope = viewModelScope
|
||||
) {
|
||||
execute(scope) {
|
||||
private fun loadWebFile(book: Book) {
|
||||
execute {
|
||||
webFiles.clear()
|
||||
val fileNameNoExtension = if (book.author.isBlank()) book.name
|
||||
else "${book.name} 作者:${book.author}"
|
||||
|
||||
Reference in New Issue
Block a user