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