This commit is contained in:
Horis
2025-05-27 13:47:16 +08:00
parent b4a5bcfcb0
commit 91c8fa2d6c
3 changed files with 18 additions and 6 deletions
@@ -122,8 +122,8 @@ interface RssSourceDao {
@Query("select * from rssSources where sourceGroup like '%' || :group || '%'")
fun getByGroup(group: String): List<RssSource>
@Query("select 1 from rssSources where sourceUrl = :key")
fun has(key: String): Boolean?
@Query("select exists(select 1 from rssSources where sourceUrl = :key)")
fun has(key: String): Boolean
@Query("update rssSources set enabled = :enable where sourceUrl = :sourceUrl")
fun enable(sourceUrl: String, enable: Boolean)
@@ -27,7 +27,7 @@ object RuleBigDataHelp {
FileUtils.delete(it)
} else {
val bookUrl = bookUrlFile.readText()
if (appDb.bookDao.has(bookUrl) != true) {
if (!appDb.bookDao.has(bookUrl)) {
FileUtils.delete(it)
}
}
@@ -42,7 +42,7 @@ object RuleBigDataHelp {
FileUtils.delete(it)
} else {
val origin = originFile.readText()
if (appDb.rssSourceDao.has(origin) != true) {
if (!appDb.rssSourceDao.has(origin)) {
FileUtils.delete(it)
}
}
@@ -76,6 +76,12 @@ object RuleBigDataHelp {
return null
}
fun hasBookVariable(bookUrl: String, key: String): Boolean {
val md5BookUrl = MD5Utils.md5Encode(bookUrl)
val md5Key = MD5Utils.md5Encode(key)
val file = File(FileUtils.getPath(bookData, md5BookUrl, "$md5Key.txt"))
return file.exists()
}
fun putChapterVariable(bookUrl: String, chapterUrl: String, key: String, value: String?) {
val md5BookUrl = MD5Utils.md5Encode(bookUrl)
@@ -14,6 +14,7 @@ import io.legado.app.data.entities.BaseBook
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookSource
import io.legado.app.exception.NoStackTraceException
import io.legado.app.help.RuleBigDataHelp
import io.legado.app.help.config.AppConfig
import io.legado.app.model.localBook.LocalBook
import io.legado.app.utils.FileDoc
@@ -268,13 +269,18 @@ fun Book.updateTo(newBook: Book): Book {
newBook.canUpdate = canUpdate
newBook.readConfig = readConfig
val variableMap = variableMap.toMutableMap()
variableMap.putAll(newBook.variableMap)
newBook.variableMap.clear()
variableMap.keys.removeIf {
newBook.hasVariable(it)
}
newBook.variableMap.putAll(variableMap)
newBook.variable = GSON.toJson(variableMap)
return newBook
}
fun Book.hasVariable(key: String): Boolean {
return variableMap.contains(key) || RuleBigDataHelp.hasBookVariable(bookUrl, key)
}
fun Book.getFolderNameNoCache(): String {
return name.replace(AppPattern.fileNameRegex, "").let {
it.substring(0, min(9, it.length)) + MD5Utils.md5Encode16(bookUrl)