This commit is contained in:
kunfei
2023-03-06 14:43:30 +08:00
parent 577ed20415
commit 9c83d7229c
7 changed files with 1855 additions and 40 deletions
+1 -1
View File
@@ -239,7 +239,7 @@ dependencies {
//加解密类库,有些书源使用 //加解密类库,有些书源使用
//noinspection GradleDependency,GradlePackageUpdate //noinspection GradleDependency,GradlePackageUpdate
implementation('cn.hutool:hutool-crypto:5.8.14') implementation('cn.hutool:hutool-crypto:5.8.12')
//firebase, 崩溃统计和性能统计, 会导致共存版本崩溃 //firebase, 崩溃统计和性能统计, 会导致共存版本崩溃
//implementation platform('com.google.firebase:firebase-bom:30.0.1') //implementation platform('com.google.firebase:firebase-bom:30.0.1')
File diff suppressed because it is too large Load Diff
@@ -1,22 +1,23 @@
package io.legado.app.data.entities package io.legado.app.data.entities
import android.os.Parcelable import android.os.Parcelable
import androidx.room.* import androidx.room.Entity
import androidx.room.PrimaryKey
import io.legado.app.utils.GSON import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject
import kotlinx.parcelize.Parcelize import kotlinx.parcelize.Parcelize
/** /**
* 服务器 * 服务器
*/ */
@Parcelize @Parcelize
@TypeConverters(Server.Converters::class)
@Entity(tableName = "servers") @Entity(tableName = "servers")
data class Server( data class Server(
@PrimaryKey @PrimaryKey
var id: Long = System.currentTimeMillis(), var id: Long = System.currentTimeMillis(),
var name: String = "", var name: String = "",
var type: TYPE = TYPE.WEBDAV, var type: TYPE = TYPE.WEBDAV,
var config: Config? = null, var config: String? = null,
var sortNumber: Int = 0 var sortNumber: Int = 0
): Parcelable { ): Parcelable {
@@ -35,20 +36,15 @@ data class Server(
return false return false
} }
@Parcelize fun getWebDavConfig(): WebDavConfig? {
data class Config( return GSON.fromJsonObject<WebDavConfig>(config).getOrNull()
/* webdav */
var username: String? = null,
var password: String? = null,
): Parcelable
class Converters {
@TypeConverter
fun configToString(config: Server.Config?): String = GSON.toJson(config)
@TypeConverter
fun stringToConfig(json: String?) = GSON.fromJsonObject<Server.Config>(json).getOrNull()
} }
@Parcelize
data class WebDavConfig(
var url: String? = null,
var username: String? = null,
var password: String? = null,
) : Parcelable
} }
@@ -1,12 +1,10 @@
package io.legado.app.lib.webdav package io.legado.app.lib.webdav
import io.legado.app.data.appDb
import io.legado.app.exception.NoStackTraceException
import okhttp3.Credentials import okhttp3.Credentials
import java.nio.charset.Charset import java.nio.charset.Charset
import java.nio.charset.StandardCharsets import java.nio.charset.StandardCharsets
import io.legado.app.data.entities.Server
import io.legado.app.data.entities.Server.TYPE
import io.legado.app.data.appDb
import io.legado.app.exception.NoStackTraceException
data class Authorization( data class Authorization(
val username: String, val username: String,
@@ -26,16 +24,8 @@ data class Authorization(
constructor(serverID: Long?): this("","") { constructor(serverID: Long?): this("","") {
serverID ?: throw NoStackTraceException("Unexpected server ID") serverID ?: throw NoStackTraceException("Unexpected server ID")
appDb.serverDao.get(serverID!!)?.run { appDb.serverDao.get(serverID)?.getWebDavConfig().run {
when (type) { data = Credentials.basic(username, password, charset)
TYPE.WEBDAV -> data = Credentials.basic(config.username, config.password, charset)
TYPE.ALIYUN -> {
TODO("not implemented")
}
TYPE.GOOGLEYUN -> {
TODO("not implemented")
}
}
} }
} }
@@ -3,7 +3,6 @@ package io.legado.app.lib.webdav
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.net.Uri import android.net.Uri
import io.legado.app.constant.AppLog import io.legado.app.constant.AppLog
import io.legado.app.data.entities.Server
import io.legado.app.exception.NoStackTraceException import io.legado.app.exception.NoStackTraceException
import io.legado.app.help.http.newCallResponse import io.legado.app.help.http.newCallResponse
import io.legado.app.help.http.okHttpClient import io.legado.app.help.http.okHttpClient
@@ -34,7 +33,7 @@ import java.time.format.DateTimeFormatter
@Suppress("unused", "MemberVisibilityCanBePrivate") @Suppress("unused", "MemberVisibilityCanBePrivate")
open class WebDav( open class WebDav(
val path: String, val path: String,
val authorization: Authorization? = Authorization(AnalyzeUrl(path).serverID) val authorization: Authorization = Authorization(AnalyzeUrl(path).serverID)
) { ) {
companion object { companion object {
@@ -774,8 +774,8 @@ class AnalyzeUrl(
return js return js
} }
fun setServerID(value: Long?) { fun setServerID(value: String?) {
serverID = if (value.isNullOrBlank()) null else value serverID = if (value.isNullOrBlank()) null else value.toLong()
} }
fun getServerID(): Long? { fun getServerID(): Long? {
@@ -340,16 +340,16 @@ object LocalBook {
AppConfig.defaultBookTreeUri AppConfig.defaultBookTreeUri
?: throw NoStackTraceException("没有设置书籍保存位置!") ?: throw NoStackTraceException("没有设置书籍保存位置!")
// 兼容旧版链接 // 兼容旧版链接
val webdav = kotlin.runCatching { val webdav: WebDav = kotlin.runCatching {
WebDav(webDavUrl) WebDav(webDavUrl)
}.onFailure { }.onFailure {
AppWebDav.defaultBookWebDav AppWebDav.defaultBookWebDav
?: throw WebDavException("Unexpected defaultBookWebDav") ?: throw WebDavException("Unexpected defaultBookWebDav")
} }.getOrThrow()
val uri = runBlocking { val uri = runBlocking {
saveBookFile(webdav.downloadInputStream(), localBook.originName) saveBookFile(webdav.downloadInputStream(), localBook.originName)
} }
return uri?.let { return uri.let {
localBook.bookUrl = if (it.isContentScheme()) it.toString() else it.path!! localBook.bookUrl = if (it.isContentScheme()) it.toString() else it.path!!
localBook.save() localBook.save()
localBook.cacheLocalUri(it) localBook.cacheLocalUri(it)