pull/1274/head
gedoor 3 years ago
parent cced256088
commit 3d5a31116d
  1. 2
      app/build.gradle
  2. 1459
      app/schemas/io.legado.app.data.AppDatabase/37.json
  3. 2
      app/src/main/java/io/legado/app/data/AppDatabase.kt
  4. 11
      app/src/main/java/io/legado/app/data/DatabaseMigrations.kt
  5. 9
      app/src/main/java/io/legado/app/data/entities/BaseSource.kt
  6. 21
      app/src/main/java/io/legado/app/data/entities/RssSource.kt
  7. 7
      app/src/main/java/io/legado/app/help/BookSourceAnalyzer.kt
  8. 10
      app/src/main/java/io/legado/app/ui/login/RuleUiLoginDialog.kt

@ -162,7 +162,7 @@ dependencies {
implementation("androidx.lifecycle:lifecycle-common-java8:$lifecycle_version")
//room
def room_version = '2.4.0-alpha04'
def room_version = '2.3.0'
implementation("androidx.room:room-runtime:$room_version")
implementation("androidx.room:room-ktx:$room_version")
kapt("androidx.room:room-compiler:$room_version")

File diff suppressed because it is too large Load Diff

@ -16,7 +16,7 @@ val appDb by lazy {
}
@Database(
version = 36,
version = 37,
exportSchema = true,
entities = [Book::class, BookGroup::class, BookSource::class, BookChapter::class,
ReplaceRule::class, SearchBook::class, SearchKeyword::class, Cookie::class,

@ -32,7 +32,8 @@ object DatabaseMigrations {
migration_32_33,
migration_33_34,
migration_34_35,
migration_35_36
migration_35_36,
migration_36_37
)
}
@ -287,4 +288,12 @@ object DatabaseMigrations {
database.execSQL("ALTER TABLE `book_sources` ADD`loginCheckJs` TEXT")
}
}
private val migration_36_37 = object : Migration(36, 37) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE `rssSources` ADD `loginUrl` TEXT")
database.execSQL("ALTER TABLE `rssSources` ADD `loginUi` TEXT")
database.execSQL("ALTER TABLE `rssSources` ADD`loginCheckJs` TEXT")
}
}
}

@ -69,13 +69,16 @@ interface BaseSource : JsExtensions {
* 获取用户信息,可以用来登录
* 用户信息采用aes加密存储
*/
fun getLoginInfo(): Map<String, String>? {
fun getLoginInfo(): String? {
val cache = CacheManager.get("userInfo_${getStoreUrl()}") ?: return null
val byteArrayB = Base64.decode(cache, Base64.DEFAULT)
val byteArrayA = EncoderUtils.decryptAES(byteArrayB, AppConst.androidId.toByteArray())
?: return null
val info = String(byteArrayA)
return GSON.fromJsonObject(info)
return String(byteArrayA)
}
fun getLoginInfoMap(): Map<String, String>? {
return GSON.fromJsonObject(getLoginInfo())
}
/**

@ -1,14 +1,16 @@
package io.legado.app.data.entities
import android.os.Parcelable
import androidx.room.Entity
import androidx.room.Index
import androidx.room.PrimaryKey
import androidx.room.*
import io.legado.app.data.entities.rule.RowUi
import io.legado.app.utils.ACache
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonArray
import kotlinx.parcelize.Parcelize
import splitties.init.appCtx
@Parcelize
@TypeConverters(RssSource.Converters::class)
@Entity(tableName = "rssSources", indices = [(Index(value = ["sourceUrl"], unique = false))])
data class RssSource(
@PrimaryKey
@ -18,6 +20,10 @@ data class RssSource(
var sourceGroup: String? = null,
var sourceComment: String? = null,
var enabled: Boolean = true,
override var header: String? = null, // 请求头
var loginUrl: String? = null, // 登录地址
var loginUi: List<RowUi>? = null, //登录UI
var loginCheckJs: String? = null, //登录检测js
var sortUrl: String? = null,
var singleUrl: Boolean = false,
var articleStyle: Int = 0,
@ -32,7 +38,6 @@ data class RssSource(
var ruleLink: String? = null,
var ruleContent: String? = null,
var style: String? = null,
override var header: String? = null,
var enableJs: Boolean = false,
var loadWithBaseUrl: Boolean = false,
@ -100,4 +105,12 @@ data class RssSource(
}
}
}
class Converters {
@TypeConverter
fun loginUiRuleToString(loginUi: List<RowUi>?): String = GSON.toJson(loginUi)
@TypeConverter
fun stringToLoginRule(json: String?): List<RowUi>? = GSON.fromJsonArray(json)
}
}

@ -230,9 +230,12 @@ object BookSourceAnalyzer {
private fun toNewUrls(oldUrls: String?): String? {
if (oldUrls.isNullOrBlank()) return null
if (!oldUrls.contains("\n") && !oldUrls.contains("&&"))
if (oldUrls.startsWith("@js:") || oldUrls.startsWith("<js>")) {
return oldUrls
}
if (!oldUrls.contains("\n") && !oldUrls.contains("&&")) {
return toNewUrl(oldUrls)
}
val urls = oldUrls.split("(&&|\r?\n)+".toRegex())
return urls.map {
toNewUrl(it)?.replace("\n\\s*".toRegex(), "")

@ -42,7 +42,7 @@ class RuleUiLoginDialog : BaseDialogFragment() {
binding.toolBar.setBackgroundColor(primaryColor)
val bookSource = viewModel.bookSource ?: return
binding.toolBar.title = getString(R.string.login_source, bookSource.bookSourceName)
val loginInfo = bookSource.getLoginInfo()
val loginInfo = bookSource.getLoginInfoMap()
val loginUi = bookSource.loginUi
loginUi?.forEachIndexed { index, rowUi ->
when (rowUi.type) {
@ -70,8 +70,8 @@ class RuleUiLoginDialog : BaseDialogFragment() {
}
binding.toolBar.inflateMenu(R.menu.source_login)
binding.toolBar.menu.applyTint(requireContext())
binding.toolBar.setOnMenuItemClickListener {
when (it.itemId) {
binding.toolBar.setOnMenuItemClickListener { item ->
when (item.itemId) {
R.id.menu_ok -> {
val loginData = hashMapOf<String, String?>()
loginUi?.forEachIndexed { index, rowUi ->
@ -84,6 +84,10 @@ class RuleUiLoginDialog : BaseDialogFragment() {
}
}
bookSource.putLoginInfo(GSON.toJson(loginData))
bookSource.loginUrl?.let {
bookSource.evalJS(it)
}
}
}
return@setOnMenuItemClickListener true

Loading…
Cancel
Save