From 8ede13f6aa3d221af70782f8940c60163545efa4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 20 Sep 2022 16:56:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/help/source/RssSourceExtensions.kt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/source/RssSourceExtensions.kt b/app/src/main/java/io/legado/app/help/source/RssSourceExtensions.kt index e181de0e2..cd712f630 100644 --- a/app/src/main/java/io/legado/app/help/source/RssSourceExtensions.kt +++ b/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) } -suspend fun RssSource.sortUrls(): List> = - arrayListOf>().apply { +suspend fun RssSource.sortUrls(): List> { + return arrayListOf>().apply { val sortUrlsKey = getSortUrlsKey() withContext(Dispatchers.IO) { kotlin.runCatching { - var a = sortUrl + var str = sortUrl if (sortUrl?.startsWith("", false) == true || sortUrl?.startsWith("@js:", false) == true ) { - a = aCache.getAsString(sortUrlsKey) ?: "" - if (a.isBlank()) { + str = aCache.getAsString(sortUrlsKey) + if (str.isNullOrBlank()) { val jsStr = if (sortUrl!!.startsWith("@")) { sortUrl!!.substring(4) } else { sortUrl!!.substring(4, sortUrl!!.lastIndexOf("<")) } - a = evalJS(jsStr).toString() - aCache.put(sortUrlsKey, a) + str = evalJS(jsStr).toString() + aCache.put(sortUrlsKey, str) } } - a?.split("(&&|\n)+".toRegex())?.forEach { c -> + str?.split("(&&|\n)+".toRegex())?.forEach { c -> val d = c.split("::") if (d.size > 1) add(Pair(d[0], d[1])) @@ -43,6 +43,7 @@ suspend fun RssSource.sortUrls(): List> = } } } +} suspend fun RssSource.removeSortCache() { withContext(Dispatchers.IO) {