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
import io.legado.app.model.NoStackTraceException
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.model.analyzeRule.RuleData
@ -17,18 +18,18 @@ object DirectLinkUpload {
suspend fun upLoad(fileName: String, file: ByteArray, contentType: String): String {
val url = getUploadUrl()
if (url.isNullOrBlank()) {
error("上传url未配置")
throw NoStackTraceException("上传url未配置")
}
val downloadUrlRule = getDownloadUrlRule()
if (downloadUrlRule.isNullOrBlank()) {
error("下载地址规则未配置")
throw NoStackTraceException("下载地址规则未配置")
}
val analyzeUrl = AnalyzeUrl(url)
val res = analyzeUrl.upload(fileName, file, contentType)
val analyzeRule = AnalyzeRule(RuleData()).setContent(res.body, res.url)
val downloadUrl = analyzeRule.getString(downloadUrlRule)
if (downloadUrl.isBlank()) {
error("上传失败,${res.body}")
throw NoStackTraceException("上传失败,${res.body}")
}
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.webdav.HttpAuth
import io.legado.app.lib.webdav.WebDav
import io.legado.app.model.NoStackTraceException
import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
@ -65,7 +66,7 @@ object AppWebDav {
}
}
} else {
error("webDav没有配置")
throw NoStackTraceException("webDav没有配置")
}
return names
}

@ -1,13 +1,49 @@
@file:Suppress("unused")
package io.legado.app.model
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.help.AppConfig
import io.legado.app.help.BookHelp
import io.legado.app.model.AppException
import io.legado.app.model.TocEmptyException
import io.legado.app.utils.*
import splitties.init.appCtx
import java.io.File
@ -38,7 +38,7 @@ object LocalBook {
}
}
if (chapters.isEmpty()) {
throw AppException(appCtx.getString(R.string.chapter_list_empty))
throw TocEmptyException(appCtx.getString(R.string.chapter_list_empty))
}
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.BookSource
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.TocEmptyException
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl
import kotlinx.coroutines.CoroutineScope
@ -101,7 +101,7 @@ object BookChapterList {
}
}
if (chapterList.isEmpty()) {
throw AppException(appCtx.getString(R.string.chapter_list_empty))
throw TocEmptyException(appCtx.getString(R.string.chapter_list_empty))
}
//去重
if (!reverse) {

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

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

Loading…
Cancel
Save