pull/2314/head
kunfei 2 years ago
parent 6e28c60491
commit 8ede13f6aa
  1. 17
      app/src/main/java/io/legado/app/help/source/RssSourceExtensions.kt

@ -12,27 +12,27 @@ private fun RssSource.getSortUrlsKey(): String {
return MD5Utils.md5Encode(sourceUrl + sortUrl) return MD5Utils.md5Encode(sourceUrl + sortUrl)
} }
suspend fun RssSource.sortUrls(): List<Pair<String, String>> = suspend fun RssSource.sortUrls(): List<Pair<String, String>> {
arrayListOf<Pair<String, String>>().apply { return arrayListOf<Pair<String, String>>().apply {
val sortUrlsKey = getSortUrlsKey() val sortUrlsKey = getSortUrlsKey()
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
kotlin.runCatching { kotlin.runCatching {
var a = sortUrl var str = sortUrl
if (sortUrl?.startsWith("<js>", false) == true if (sortUrl?.startsWith("<js>", false) == true
|| sortUrl?.startsWith("@js:", false) == true || sortUrl?.startsWith("@js:", false) == true
) { ) {
a = aCache.getAsString(sortUrlsKey) ?: "" str = aCache.getAsString(sortUrlsKey)
if (a.isBlank()) { if (str.isNullOrBlank()) {
val jsStr = if (sortUrl!!.startsWith("@")) { val jsStr = if (sortUrl!!.startsWith("@")) {
sortUrl!!.substring(4) sortUrl!!.substring(4)
} else { } else {
sortUrl!!.substring(4, sortUrl!!.lastIndexOf("<")) sortUrl!!.substring(4, sortUrl!!.lastIndexOf("<"))
} }
a = evalJS(jsStr).toString() str = evalJS(jsStr).toString()
aCache.put(sortUrlsKey, a) aCache.put(sortUrlsKey, str)
} }
} }
a?.split("(&&|\n)+".toRegex())?.forEach { c -> str?.split("(&&|\n)+".toRegex())?.forEach { c ->
val d = c.split("::") val d = c.split("::")
if (d.size > 1) if (d.size > 1)
add(Pair(d[0], d[1])) add(Pair(d[0], d[1]))
@ -43,6 +43,7 @@ suspend fun RssSource.sortUrls(): List<Pair<String, String>> =
} }
} }
} }
}
suspend fun RssSource.removeSortCache() { suspend fun RssSource.removeSortCache() {
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {

Loading…
Cancel
Save