pull/2706/head
kunfei 2 years ago
parent 17e0544e07
commit a5f45e9e98
  1. 23
      app/src/main/java/io/legado/app/data/entities/BaseSource.kt
  2. 8
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt

@ -52,8 +52,8 @@ interface BaseSource : JsExtensions {
fun loginUi(): List<RowUi>? { fun loginUi(): List<RowUi>? {
return GSON.fromJsonArray<RowUi>(loginUi).onFailure { return GSON.fromJsonArray<RowUi>(loginUi).onFailure {
it.printOnDebug() it.printOnDebug()
}.getOrNull() }.getOrNull()
} }
fun getLoginJs(): String? { fun getLoginJs(): String? {
@ -66,7 +66,9 @@ interface BaseSource : JsExtensions {
} }
} }
// 调用login函数 实现登录请求 /**
* 调用login函数 实现登录请求
*/
fun login() { fun login() {
val loginJs = getLoginJs() val loginJs = getLoginJs()
if (!loginJs.isNullOrBlank()) { if (!loginJs.isNullOrBlank()) {
@ -198,6 +200,21 @@ interface BaseSource : JsExtensions {
return CacheManager.get("sourceVariable_${getKey()}") return CacheManager.get("sourceVariable_${getKey()}")
} }
/**
* 保存数据
*/
fun put(key: String, value: String): String {
CacheManager.put("v_${getKey()}_${key}", value)
return value
}
/**
* 获取保存的数据
*/
fun get(key: String): String {
return CacheManager.get("v_${getKey()}_${key}") ?: ""
}
/** /**
* 执行JS * 执行JS
*/ */

@ -610,13 +610,20 @@ class AnalyzeRule(
XPath, Json, Default, Js, Regex XPath, Json, Default, Js, Regex
} }
/**
* 保存数据
*/
fun put(key: String, value: String): String { fun put(key: String, value: String): String {
chapter?.putVariable(key, value) chapter?.putVariable(key, value)
?: book?.putVariable(key, value) ?: book?.putVariable(key, value)
?: ruleData?.putVariable(key, value) ?: ruleData?.putVariable(key, value)
?: source?.put(key, value)
return value return value
} }
/**
* 获取保存的数据
*/
fun get(key: String): String { fun get(key: String): String {
when (key) { when (key) {
"bookName" -> book?.let { "bookName" -> book?.let {
@ -629,6 +636,7 @@ class AnalyzeRule(
return chapter?.getVariable(key) return chapter?.getVariable(key)
?: book?.getVariable(key) ?: book?.getVariable(key)
?: ruleData?.getVariable(key) ?: ruleData?.getVariable(key)
?: source?.get(key)
?: "" ?: ""
} }

Loading…
Cancel
Save