Xwite 3 лет назад
Родитель
Сommit
78bf12dc65

+ 2 - 1
app/src/main/java/io/legado/app/help/book/BookExtensions.kt

@@ -62,7 +62,8 @@ val Book.archiveName: String?
     get() {
         return if (isArchive) {
             // local_book::archive.rar
-            origin.substring(BookType.localTag.length + 2)
+            // webDav::https://...../archive.rar
+            origin.substringAfter("::").substringAfterLast("/")
         } else {
             null
         }

+ 16 - 1
app/src/main/java/io/legado/app/model/localBook/LocalBook.kt

@@ -213,12 +213,27 @@ object LocalBook {
     }
 
    /* 批量导入 支持自动导入压缩包的支持书籍 */
+    fun importFiles(uri: Uri): List<Book> {
+        val books = mutableListOf<Book>()
+        val fileDoc = FileDoc.fromUri(uri, false)
+        if (ArchiveUtils.isArchive(fileDoc.name)) {
+            books.addAll(
+                importArchiveFile(uri) {
+                    it.matches(AppPattern.bookFileRegex)
+                }
+            )
+        } else {
+            books.add(importFile(uri))
+        }
+        return books
+    }
+
     fun importFiles(uris: List<Uri>) {
         var errorCount = 0
         uris.forEach { uri ->
             val fileDoc = FileDoc.fromUri(uri, false)
             kotlin.runCatching {
-               if (ArchiveUtils.isArchive(fileDoc.name)) {
+                if (ArchiveUtils.isArchive(fileDoc.name)) {
                     importArchiveFile(uri) {
                         it.matches(AppPattern.bookFileRegex)
                     }

+ 3 - 1
app/src/main/java/io/legado/app/model/remote/RemoteBookWebDav.kt

@@ -1,6 +1,7 @@
 package io.legado.app.model.remote
 
 import android.net.Uri
+import io.legado.app.constant.AppPattern.archiveFileRegex
 import io.legado.app.constant.AppPattern.bookFileRegex
 import io.legado.app.constant.BookType
 import io.legado.app.data.entities.Book
@@ -39,7 +40,8 @@ class RemoteBookWebDav(
         val remoteWebDavFileList: List<WebDavFile> = WebDav(path, authorization).listFiles()
         //转化远程文件信息到本地对象
         remoteWebDavFileList.forEach { webDavFile ->
-            if (webDavFile.isDir || bookFileRegex.matches(webDavFile.displayName)) {
+            if (webDavFile.isDir || bookFileRegex.matches(webDavFile.displayName) || archiveFileRegex.matches(webDavFile.displayName)
+            ) {
                 //扩展名符合阅读的格式则认为是书籍
                 remoteBooks.add(RemoteBook(webDavFile))
             }

+ 6 - 7
app/src/main/java/io/legado/app/ui/book/import/remote/RemoteBookViewModel.kt

@@ -124,18 +124,17 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
 
     fun addToBookshelf(remoteBooks: HashSet<RemoteBook>, finally: () -> Unit) {
         execute {
+            val bookWebDav = remoteBookWebDav
+                ?: throw NoStackTraceException("没有配置webDav")
             remoteBooks.forEach { remoteBook ->
-                val bookWebDav = remoteBookWebDav
-                    ?: throw NoStackTraceException("没有配置webDav")
-                val downloadBookPath = bookWebDav.downloadRemoteBook(remoteBook)
-                downloadBookPath.let {
-                    val localBook = LocalBook.importFile(it)
-                    localBook.origin = BookType.webDavTag + CustomUrl(remoteBook.path)
+                val downloadBookUri = bookWebDav.downloadRemoteBook(remoteBook)
+                LocalBook.importFiles(downloadBookUri).forEach { book ->
+                    book.origin = BookType.webDavTag + CustomUrl(remoteBook.path)
                         .putAttribute(
                             "serverID",
                             bookWebDav.serverID
                         ).toString()
-                    localBook.save()
+                    book.save()
                     remoteBook.isOnBookShelf = true
                 }
             }

+ 1 - 1
app/src/main/java/io/legado/app/utils/UrlUtil.kt

@@ -82,7 +82,7 @@ object UrlUtil {
             val headersString = buildString {
                 headers.forEach { (key, value) ->
                    value.forEach {
-                       append(key ?: "HEAD ${url.toString}")
+                       append(key)
                        append(": ")
                        append(it)
                        append("\n")