pull/1705/head
parent
f32710001c
commit
bd28d402ed
@ -1,29 +1,101 @@ |
|||||||
package io.legado.app.help |
package io.legado.app.help |
||||||
|
|
||||||
|
import io.legado.app.utils.FileUtils |
||||||
|
import io.legado.app.utils.MD5Utils |
||||||
|
import io.legado.app.utils.externalFiles |
||||||
|
import splitties.init.appCtx |
||||||
|
import java.io.File |
||||||
|
|
||||||
object RuleBigDataHelp { |
object RuleBigDataHelp { |
||||||
|
|
||||||
fun putBookVariable(bookUrl: String, key: String, value: String?) { |
private val ruleDataDir = FileUtils.createFolderIfNotExist(appCtx.externalFiles, "ruleData") |
||||||
|
private val bookData = FileUtils.createFolderIfNotExist(ruleDataDir, "book") |
||||||
|
private val rssData = FileUtils.createFolderIfNotExist(ruleDataDir, "rss") |
||||||
|
|
||||||
|
fun putBookVariable(bookUrl: String, key: String, value: String?) { |
||||||
|
val md5BookUrl = MD5Utils.md5Encode(bookUrl) |
||||||
|
val md5Key = MD5Utils.md5Encode(key) |
||||||
|
if (value == null) { |
||||||
|
FileUtils.delete(FileUtils.getPath(bookData, md5BookUrl, "$md5Key.txt"), true) |
||||||
|
} else { |
||||||
|
val valueFile = FileUtils.createFileIfNotExist(bookData, md5BookUrl, "$md5Key.txt") |
||||||
|
valueFile.writeText(value) |
||||||
|
val bookUrlFile = File(FileUtils.getPath(bookData, md5BookUrl, "bookUrl.txt")) |
||||||
|
if (!bookUrlFile.exists()) { |
||||||
|
bookUrlFile.writeText(bookUrl) |
||||||
|
} |
||||||
|
} |
||||||
} |
} |
||||||
|
|
||||||
fun getBookVariable(bookUrl: String, key: String?): String? { |
fun getBookVariable(bookUrl: String, key: String?): String? { |
||||||
|
val md5BookUrl = MD5Utils.md5Encode(bookUrl) |
||||||
|
val md5Key = MD5Utils.md5Encode(key) |
||||||
|
val file = File(FileUtils.getPath(bookData, md5BookUrl, "$md5Key.txt")) |
||||||
|
if (file.exists()) { |
||||||
|
return file.readText() |
||||||
|
} |
||||||
return null |
return null |
||||||
} |
} |
||||||
|
|
||||||
|
|
||||||
fun putChapterVariable(bookUrl: String, chapterUrl: String, key: String, value: String?) { |
fun putChapterVariable(bookUrl: String, chapterUrl: String, key: String, value: String?) { |
||||||
|
val md5BookUrl = MD5Utils.md5Encode(bookUrl) |
||||||
|
val md5ChapterUrl = MD5Utils.md5Encode(chapterUrl) |
||||||
|
val md5Key = MD5Utils.md5Encode(key) |
||||||
|
if (value == null) { |
||||||
|
FileUtils.delete(FileUtils.getPath(bookData, md5BookUrl, md5ChapterUrl, "$md5Key.txt")) |
||||||
|
} else { |
||||||
|
val valueFile = |
||||||
|
FileUtils.createFileIfNotExist(bookData, md5BookUrl, md5ChapterUrl, "$md5Key.txt") |
||||||
|
valueFile.writeText(value) |
||||||
|
val bookUrlFile = File(FileUtils.getPath(bookData, md5BookUrl, "bookUrl.txt")) |
||||||
|
if (!bookUrlFile.exists()) { |
||||||
|
bookUrlFile.writeText(bookUrl) |
||||||
|
} |
||||||
|
} |
||||||
} |
} |
||||||
|
|
||||||
fun getChapterVariable(bookUrl: String, chapterUrl: String, key: String): String? { |
fun getChapterVariable(bookUrl: String, chapterUrl: String, key: String): String? { |
||||||
|
val md5BookUrl = MD5Utils.md5Encode(bookUrl) |
||||||
|
val md5ChapterUrl = MD5Utils.md5Encode(chapterUrl) |
||||||
|
val md5Key = MD5Utils.md5Encode(key) |
||||||
|
val file = File(FileUtils.getPath(bookData, md5BookUrl, md5ChapterUrl, "$md5Key.txt")) |
||||||
|
if (file.exists()) { |
||||||
|
return file.readText() |
||||||
|
} |
||||||
return null |
return null |
||||||
} |
} |
||||||
|
|
||||||
fun putRssVariable(origin: String, link: String, key: String, value: String?) { |
fun putRssVariable(origin: String, link: String, key: String, value: String?) { |
||||||
|
val md5Origin = MD5Utils.md5Encode(origin) |
||||||
|
val md5Link = MD5Utils.md5Encode(link) |
||||||
|
val md5Key = MD5Utils.md5Encode(key) |
||||||
|
val filePath = FileUtils.getPath(rssData, md5Origin, md5Link, "$md5Key.txt") |
||||||
|
if (value == null) { |
||||||
|
FileUtils.delete(filePath) |
||||||
|
} else { |
||||||
|
val valueFile = FileUtils.createFileIfNotExist(filePath) |
||||||
|
valueFile.writeText(value) |
||||||
|
val originFile = File(FileUtils.getPath(rssData, md5Origin, "origin.txt")) |
||||||
|
if (!originFile.exists()) { |
||||||
|
originFile.writeText(origin) |
||||||
|
} |
||||||
|
val linFile = File(FileUtils.getPath(rssData, md5Origin, md5Link, "origin.txt")) |
||||||
|
if (!linFile.exists()) { |
||||||
|
linFile.writeText(link) |
||||||
|
} |
||||||
|
} |
||||||
} |
} |
||||||
|
|
||||||
fun getRssVariable(origin: String, link: String, key: String): String? { |
fun getRssVariable(origin: String, link: String, key: String): String? { |
||||||
|
val md5Origin = MD5Utils.md5Encode(origin) |
||||||
|
val md5Link = MD5Utils.md5Encode(link) |
||||||
|
val md5Key = MD5Utils.md5Encode(key) |
||||||
|
val filePath = FileUtils.getPath(rssData, md5Origin, md5Link, "$md5Key.txt") |
||||||
|
val file = File(filePath) |
||||||
|
if (file.exists()) { |
||||||
|
return file.readText() |
||||||
|
} |
||||||
return null |
return null |
||||||
} |
} |
||||||
} |
} |
Loading…
Reference in new issue