mirror of
https://github.com/gedoor/legado.git
synced 2024-08-30 09:23:26 +08:00
fix: 远程书籍界面下载的书籍的没有保留服务器id
This commit is contained in:
parent
d37faa2b8a
commit
bfd94969e3
@ -33,7 +33,8 @@ import java.time.format.DateTimeFormatter
|
||||
@Suppress("unused", "MemberVisibilityCanBePrivate")
|
||||
open class WebDav(
|
||||
val path: String,
|
||||
val authorization: Authorization = Authorization(AnalyzeUrl(path).serverID)
|
||||
val authorization: Authorization = Authorization(AnalyzeUrl(path).serverID),
|
||||
private val serverID: Long? = AnalyzeUrl(path).serverID
|
||||
) {
|
||||
companion object {
|
||||
|
||||
@ -65,9 +66,8 @@ open class WebDav(
|
||||
</propfind>"""
|
||||
}
|
||||
|
||||
|
||||
private val url: URL = URL(AnalyzeUrl(path).url)
|
||||
/* 服务器id */
|
||||
private var serverID: Long? = AnalyzeUrl(path).serverID
|
||||
private val httpUrl: String? by lazy {
|
||||
val raw = url.toString()
|
||||
.replace("davs://", "https://")
|
||||
|
@ -4,7 +4,6 @@ import android.net.Uri
|
||||
import io.legado.app.constant.AppPattern.bookFileRegex
|
||||
import io.legado.app.constant.BookType
|
||||
import io.legado.app.data.entities.Book
|
||||
import io.legado.app.data.entities.Server
|
||||
import io.legado.app.exception.NoStackTraceException
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.lib.webdav.Authorization
|
||||
@ -18,8 +17,11 @@ import kotlinx.coroutines.runBlocking
|
||||
import splitties.init.appCtx
|
||||
import java.io.File
|
||||
|
||||
class RemoteBookWebDav(val rootBookUrl: String, val authorization: Authorization) :
|
||||
RemoteBookManager() {
|
||||
class RemoteBookWebDav(
|
||||
val rootBookUrl: String,
|
||||
val authorization: Authorization,
|
||||
val serverID: Long? = null
|
||||
) : RemoteBookManager() {
|
||||
|
||||
init {
|
||||
runBlocking {
|
||||
@ -27,7 +29,6 @@ class RemoteBookWebDav(val rootBookUrl: String, val authorization: Authorization
|
||||
}
|
||||
}
|
||||
|
||||
// constructor(server: WebDavServer): this(webDavServer.url, Authorization(webDavServer))
|
||||
|
||||
@Throws(Exception::class)
|
||||
override suspend fun getRemoteBookList(path: String): MutableList<RemoteBook> {
|
||||
@ -66,7 +67,7 @@ class RemoteBookWebDav(val rootBookUrl: String, val authorization: Authorization
|
||||
if (!NetworkUtils.isAvailable()) throw NoStackTraceException("网络不可用")
|
||||
val localBookUri = Uri.parse(book.bookUrl)
|
||||
val putUrl = "$rootBookUrl${File.separator}${book.originName}"
|
||||
val webDav = WebDav(putUrl, authorization)
|
||||
val webDav = WebDav(putUrl, authorization, serverID)
|
||||
if (localBookUri.isContentScheme()) {
|
||||
webDav.upload(
|
||||
byteArray = localBookUri.readBytes(appCtx),
|
||||
|
@ -86,7 +86,7 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
|
||||
val user = config.getString("user")
|
||||
val password = config.getString("password")
|
||||
val authorization = Authorization(user, password)
|
||||
remoteBookWebDav = RemoteBookWebDav(url, authorization)
|
||||
remoteBookWebDav = RemoteBookWebDav(url, authorization, 10001)
|
||||
return@execute
|
||||
}
|
||||
}
|
||||
@ -125,7 +125,7 @@ class RemoteBookViewModel(application: Application) : BaseViewModel(application)
|
||||
val downloadBookPath = bookWebDav.downloadRemoteBook(remoteBook)
|
||||
downloadBookPath.let {
|
||||
val localBook = LocalBook.importFile(it)
|
||||
localBook.origin = BookType.webDavTag + WebDav(remoteBook.path, bookWebDav.authorization).toString()
|
||||
localBook.origin = BookType.webDavTag + WebDav(remoteBook.path, serverID = bookWebDav.serverID).toString()
|
||||
localBook.save()
|
||||
remoteBook.isOnBookShelf = true
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user