pull/1336/head
gedoor 3 years ago
parent 9185963766
commit 6b38f6b118
  1. 7
      app/src/main/java/io/legado/app/help/DirectLinkUpload.kt
  2. 3
      app/src/main/java/io/legado/app/help/storage/AppWebDav.kt
  3. 40
      app/src/main/java/io/legado/app/model/Exceptions.kt
  4. 4
      app/src/main/java/io/legado/app/model/localBook/LocalBook.kt
  5. 4
      app/src/main/java/io/legado/app/model/webBook/BookChapterList.kt
  6. 3
      app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditViewModel.kt
  7. 13
      app/src/main/java/io/legado/app/utils/UriExtensions.kt

@ -1,5 +1,6 @@
package io.legado.app.help package io.legado.app.help
import io.legado.app.model.NoStackTraceException
import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.model.analyzeRule.RuleData import io.legado.app.model.analyzeRule.RuleData
@ -17,18 +18,18 @@ object DirectLinkUpload {
suspend fun upLoad(fileName: String, file: ByteArray, contentType: String): String { suspend fun upLoad(fileName: String, file: ByteArray, contentType: String): String {
val url = getUploadUrl() val url = getUploadUrl()
if (url.isNullOrBlank()) { if (url.isNullOrBlank()) {
error("上传url未配置") throw NoStackTraceException("上传url未配置")
} }
val downloadUrlRule = getDownloadUrlRule() val downloadUrlRule = getDownloadUrlRule()
if (downloadUrlRule.isNullOrBlank()) { if (downloadUrlRule.isNullOrBlank()) {
error("下载地址规则未配置") throw NoStackTraceException("下载地址规则未配置")
} }
val analyzeUrl = AnalyzeUrl(url) val analyzeUrl = AnalyzeUrl(url)
val res = analyzeUrl.upload(fileName, file, contentType) val res = analyzeUrl.upload(fileName, file, contentType)
val analyzeRule = AnalyzeRule(RuleData()).setContent(res.body, res.url) val analyzeRule = AnalyzeRule(RuleData()).setContent(res.body, res.url)
val downloadUrl = analyzeRule.getString(downloadUrlRule) val downloadUrl = analyzeRule.getString(downloadUrlRule)
if (downloadUrl.isBlank()) { if (downloadUrl.isBlank()) {
error("上传失败,${res.body}") throw NoStackTraceException("上传失败,${res.body}")
} }
return downloadUrl return downloadUrl
} }

@ -11,6 +11,7 @@ import io.legado.app.help.coroutine.Coroutine
import io.legado.app.lib.dialogs.selector import io.legado.app.lib.dialogs.selector
import io.legado.app.lib.webdav.HttpAuth import io.legado.app.lib.webdav.HttpAuth
import io.legado.app.lib.webdav.WebDav import io.legado.app.lib.webdav.WebDav
import io.legado.app.model.NoStackTraceException
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Dispatchers.Main
@ -65,7 +66,7 @@ object AppWebDav {
} }
} }
} else { } else {
error("webDav没有配置") throw NoStackTraceException("webDav没有配置")
} }
return names return names
} }

@ -1,13 +1,49 @@
@file:Suppress("unused")
package io.legado.app.model package io.legado.app.model
class AppException(msg: String) : Exception(msg) class AppException(msg: String) : Exception(msg)
/**
*
*/
class NoStackTraceException(msg: String) : Exception(msg) {
override fun fillInStackTrace(): Throwable {
return this
}
}
/**
* 目录为空
*/
class TocEmptyException(msg: String) : Exception(msg) {
override fun fillInStackTrace(): Throwable {
return this
}
}
/** /**
* 内容为空 * 内容为空
*/ */
class ContentEmptyException(msg: String) : Exception(msg) class ContentEmptyException(msg: String) : Exception(msg) {
override fun fillInStackTrace(): Throwable {
return this
}
}
/** /**
* 并发限制 * 并发限制
*/ */
class ConcurrentException(msg: String, val waitTime: Long) : Exception(msg) class ConcurrentException(msg: String, val waitTime: Long) : Exception(msg) {
override fun fillInStackTrace(): Throwable {
return this
}
}

@ -10,7 +10,7 @@ import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.model.AppException import io.legado.app.model.TocEmptyException
import io.legado.app.utils.* import io.legado.app.utils.*
import splitties.init.appCtx import splitties.init.appCtx
import java.io.File import java.io.File
@ -38,7 +38,7 @@ object LocalBook {
} }
} }
if (chapters.isEmpty()) { if (chapters.isEmpty()) {
throw AppException(appCtx.getString(R.string.chapter_list_empty)) throw TocEmptyException(appCtx.getString(R.string.chapter_list_empty))
} }
return chapters return chapters
} }

@ -6,8 +6,8 @@ import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.rule.TocRule import io.legado.app.data.entities.rule.TocRule
import io.legado.app.model.AppException
import io.legado.app.model.Debug import io.legado.app.model.Debug
import io.legado.app.model.TocEmptyException
import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
@ -101,7 +101,7 @@ object BookChapterList {
} }
} }
if (chapterList.isEmpty()) { if (chapterList.isEmpty()) {
throw AppException(appCtx.getString(R.string.chapter_list_empty)) throw TocEmptyException(appCtx.getString(R.string.chapter_list_empty))
} }
//去重 //去重
if (!reverse) { if (!reverse) {

@ -8,6 +8,7 @@ import io.legado.app.data.entities.BookSource
import io.legado.app.help.BookSourceAnalyzer import io.legado.app.help.BookSourceAnalyzer
import io.legado.app.help.http.newCallStrResponse import io.legado.app.help.http.newCallStrResponse
import io.legado.app.help.http.okHttpClient import io.legado.app.help.http.okHttpClient
import io.legado.app.model.NoStackTraceException
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@ -55,7 +56,7 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat
execute(context = Dispatchers.Main) { execute(context = Dispatchers.Main) {
val text = context.getClipText() val text = context.getClipText()
if (text.isNullOrBlank()) { if (text.isNullOrBlank()) {
error("剪贴板为空") throw NoStackTraceException("剪贴板为空")
} else { } else {
importSource(text, onSuccess) importSource(text, onSuccess)
} }

@ -8,6 +8,7 @@ import androidx.fragment.app.Fragment
import io.legado.app.R import io.legado.app.R
import io.legado.app.lib.permission.Permissions import io.legado.app.lib.permission.Permissions
import io.legado.app.lib.permission.PermissionsCompat import io.legado.app.lib.permission.PermissionsCompat
import io.legado.app.model.NoStackTraceException
import java.io.File import java.io.File
fun Uri.isContentScheme() = this.scheme == "content" fun Uri.isContentScheme() = this.scheme == "content"
@ -20,10 +21,10 @@ fun AppCompatActivity.readUri(uri: Uri?, success: (name: String, bytes: ByteArra
try { try {
if (uri.isContentScheme()) { if (uri.isContentScheme()) {
val doc = DocumentFile.fromSingleUri(this, uri) val doc = DocumentFile.fromSingleUri(this, uri)
doc ?: error("未获取到文件") doc ?: throw NoStackTraceException("未获取到文件")
val name = doc.name ?: error("未获取到文件名") val name = doc.name ?: throw NoStackTraceException("未获取到文件名")
val fileBytes = DocumentUtils.readBytes(this, doc.uri) val fileBytes = DocumentUtils.readBytes(this, doc.uri)
fileBytes ?: error("读取文件出错") fileBytes ?: throw NoStackTraceException("读取文件出错")
success.invoke(name, fileBytes) success.invoke(name, fileBytes)
} else { } else {
PermissionsCompat.Builder(this) PermissionsCompat.Builder(this)
@ -54,10 +55,10 @@ fun Fragment.readUri(uri: Uri?, success: (name: String, bytes: ByteArray) -> Uni
try { try {
if (uri.isContentScheme()) { if (uri.isContentScheme()) {
val doc = DocumentFile.fromSingleUri(requireContext(), uri) val doc = DocumentFile.fromSingleUri(requireContext(), uri)
doc ?: error("未获取到文件") doc ?: throw NoStackTraceException("未获取到文件")
val name = doc.name ?: error("未获取到文件名") val name = doc.name ?: throw NoStackTraceException("未获取到文件名")
val fileBytes = DocumentUtils.readBytes(requireContext(), doc.uri) val fileBytes = DocumentUtils.readBytes(requireContext(), doc.uri)
fileBytes ?: error("读取文件出错") fileBytes ?: throw NoStackTraceException("读取文件出错")
success.invoke(name, fileBytes) success.invoke(name, fileBytes)
} else { } else {
PermissionsCompat.Builder(this) PermissionsCompat.Builder(this)

Loading…
Cancel
Save