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
implementation('cn.hutool:hutool-crypto:5.8.14')
implementation('cn.hutool:hutool-crypto:5.8.12')
//firebase, 崩溃统计和性能统计, 会导致共存版本崩溃
//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
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.fromJsonObject
import kotlinx.parcelize.Parcelize
/**
* 服务器
*/
@Parcelize
@TypeConverters(Server.Converters::class)
@Entity(tableName = "servers")
data class Server(
@PrimaryKey
var id: Long = System.currentTimeMillis(),
var name: String = "",
var type: TYPE = TYPE.WEBDAV,
var config: Config? = null,
var config: String? = null,
var sortNumber: Int = 0
): Parcelable {
@@ -35,20 +36,15 @@ data class Server(
return false
}
@Parcelize
data class Config(
/* 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()
fun getWebDavConfig(): WebDavConfig? {
return GSON.fromJsonObject<WebDavConfig>(config).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
import io.legado.app.data.appDb
import io.legado.app.exception.NoStackTraceException
import okhttp3.Credentials
import java.nio.charset.Charset
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(
val username: String,
@@ -26,16 +24,8 @@ data class Authorization(
constructor(serverID: Long?): this("","") {
serverID ?: throw NoStackTraceException("Unexpected server ID")
appDb.serverDao.get(serverID!!)?.run {
when (type) {
TYPE.WEBDAV -> data = Credentials.basic(config.username, config.password, charset)
TYPE.ALIYUN -> {
TODO("not implemented")
}
TYPE.GOOGLEYUN -> {
TODO("not implemented")
}
}
appDb.serverDao.get(serverID)?.getWebDavConfig().run {
data = Credentials.basic(username, password, charset)
}
}
@@ -3,7 +3,6 @@ package io.legado.app.lib.webdav
import android.annotation.SuppressLint
import android.net.Uri
import io.legado.app.constant.AppLog
import io.legado.app.data.entities.Server
import io.legado.app.exception.NoStackTraceException
import io.legado.app.help.http.newCallResponse
import io.legado.app.help.http.okHttpClient
@@ -34,7 +33,7 @@ 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)
) {
companion object {
@@ -774,8 +774,8 @@ class AnalyzeUrl(
return js
}
fun setServerID(value: Long?) {
serverID = if (value.isNullOrBlank()) null else value
fun setServerID(value: String?) {
serverID = if (value.isNullOrBlank()) null else value.toLong()
}
fun getServerID(): Long? {
@@ -340,16 +340,16 @@ object LocalBook {
AppConfig.defaultBookTreeUri
?: throw NoStackTraceException("没有设置书籍保存位置!")
// 兼容旧版链接
val webdav = kotlin.runCatching {
val webdav: WebDav = kotlin.runCatching {
WebDav(webDavUrl)
}.onFailure {
AppWebDav.defaultBookWebDav
?: throw WebDavException("Unexpected defaultBookWebDav")
}
val uri = runBlocking {
}.getOrThrow()
val uri = runBlocking {
saveBookFile(webdav.downloadInputStream(), localBook.originName)
}
return uri?.let {
return uri.let {
localBook.bookUrl = if (it.isContentScheme()) it.toString() else it.path!!
localBook.save()
localBook.cacheLocalUri(it)