mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
feat(book/remote): implements isOnBookShelf and use regex to judge
booktype
This commit is contained in:
@@ -219,6 +219,8 @@ object LocalBook {
|
||||
fileName: String,
|
||||
source: BaseSource? = null,
|
||||
): Uri {
|
||||
AppConfig.defaultBookTreeUri
|
||||
?: throw NoStackTraceException("没有设置书籍保存位置!")
|
||||
val bytes = when {
|
||||
str.isAbsUrl() -> AnalyzeUrl(str, source = source).getByteArray()
|
||||
str.isDataUrl() -> Base64.decode(str.substringAfter("base64,"), Base64.DEFAULT)
|
||||
@@ -269,6 +271,26 @@ object LocalBook {
|
||||
}
|
||||
}
|
||||
|
||||
fun isOnBookShelf(
|
||||
fileName: String
|
||||
): Boolean {
|
||||
val defaultBookTreeUri = AppConfig.defaultBookTreeUri
|
||||
if (defaultBookTreeUri.isNullOrBlank()) throw NoStackTraceException("没有设置书籍保存位置!")
|
||||
val treeUri = Uri.parse(defaultBookTreeUri)
|
||||
var bookUrl: String = ""
|
||||
if (treeUri.isContentScheme()) {
|
||||
val treeDoc = DocumentFile.fromTreeUri(appCtx, treeUri)
|
||||
var doc = treeDoc!!.findFile(fileName) ?: return false
|
||||
bookUrl = doc.uri.toString()
|
||||
} else {
|
||||
val treeFile = File(treeUri.path!!)
|
||||
val file = treeFile.getFile(fileName)
|
||||
if (!file.exists()) return false
|
||||
bookUrl = file.absolutePath
|
||||
}
|
||||
return appDb.bookDao.getBook(bookUrl) != null
|
||||
}
|
||||
|
||||
//文件类书源 合并在线书籍信息 在线 > 本地
|
||||
fun mergeBook(localBook: Book, onLineBook: Book?): Book {
|
||||
onLineBook ?: return localBook
|
||||
|
||||
@@ -5,5 +5,6 @@ data class RemoteBook(
|
||||
val urlName: String,
|
||||
val size: Long,
|
||||
val contentType: String,
|
||||
val lastModify: Long
|
||||
val lastModify: Long,
|
||||
val isOnBookShelf: Boolean
|
||||
)
|
||||
@@ -2,11 +2,8 @@ package io.legado.app.ui.book.remote
|
||||
|
||||
import android.net.Uri
|
||||
|
||||
|
||||
|
||||
abstract class RemoteBookManager {
|
||||
protected val remoteBookFolder : String = "books"
|
||||
protected val contentTypeList: ArrayList<String> = arrayListOf("epub","txt")
|
||||
abstract suspend fun initRemoteContext()
|
||||
abstract suspend fun getRemoteBookList(): MutableList<RemoteBook>
|
||||
abstract suspend fun upload(localBookUri: Uri): Boolean
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.legado.app.ui.book.remote.manager
|
||||
|
||||
import android.net.Uri
|
||||
import io.legado.app.constant.PreferKey
|
||||
import io.legado.app.constant.AppPattern.bookFileRegex
|
||||
import io.legado.app.exception.NoStackTraceException
|
||||
import io.legado.app.help.AppWebDav
|
||||
import io.legado.app.help.config.AppConfig
|
||||
@@ -68,8 +69,14 @@ object RemoteBookWebDav : RemoteBookManager() {
|
||||
val fileExtension = webDavFileName.substringAfterLast(".")
|
||||
|
||||
//扩展名符合阅读的格式则认为是书籍
|
||||
if (contentTypeList.contains(fileExtension)) {
|
||||
remoteBooks.add(RemoteBook(webDavFileName,webDavUrlName,webDavFile.size,fileExtension,webDavFile.lastModify))
|
||||
if (bookFileRegex.matches(webDavFileName)) {
|
||||
val isOnBookShelf = LocalBook.isOnBookShelf(webDavFileName)
|
||||
remoteBooks.add(
|
||||
RemoteBook(
|
||||
webDavFileName, webDavUrlName, webDavFile.size,
|
||||
fileExtension, webDavFile.lastModify, isOnBookShelf
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
} ?: throw NoStackTraceException("webDav没有配置")
|
||||
|
||||
Reference in New Issue
Block a user