pull/2114/head
kunfei 2 years ago
parent 1e6f0e5b97
commit 4861d71dc1
  1. 15
      app/src/main/java/io/legado/app/help/DirectLinkUpload.kt
  2. 2
      app/src/main/java/io/legado/app/help/storage/Backup.kt
  3. 6
      app/src/main/java/io/legado/app/ui/config/DirectLinkUploadConfig.kt

@ -16,7 +16,7 @@ object DirectLinkUpload {
@Throws(NoStackTraceException::class) @Throws(NoStackTraceException::class)
suspend fun upLoad(fileName: String, file: Any, contentType: String): String { suspend fun upLoad(fileName: String, file: Any, contentType: String): String {
val rule = defaultRule ?: getConfigRule() val rule = getRule()
rule ?: throw NoStackTraceException("直链上传规则未配置") rule ?: throw NoStackTraceException("直链上传规则未配置")
val url = rule.uploadUrl val url = rule.uploadUrl
if (url.isBlank()) { if (url.isBlank()) {
@ -44,22 +44,27 @@ object DirectLinkUpload {
GSON.fromJsonObject<Rule>(json).getOrNull() GSON.fromJsonObject<Rule>(json).getOrNull()
} }
fun getConfigRule(): Rule? { fun getRule(): Rule? {
val json = ACache.get(cacheDir = false).getAsString(ruleFileName)
return GSON.fromJsonObject<Rule>(json).getOrNull() ?: defaultRule
}
fun getConfig(): Rule? {
val json = ACache.get(cacheDir = false).getAsString(ruleFileName) val json = ACache.get(cacheDir = false).getAsString(ruleFileName)
return GSON.fromJsonObject<Rule>(json).getOrNull() return GSON.fromJsonObject<Rule>(json).getOrNull()
} }
fun putConfigRule(uploadUrl: String, downloadUrlRule: String, summary: String?) { fun putConfig(uploadUrl: String, downloadUrlRule: String, summary: String?) {
val rule = Rule(uploadUrl, downloadUrlRule, summary) val rule = Rule(uploadUrl, downloadUrlRule, summary)
ACache.get(cacheDir = false).put(ruleFileName, GSON.toJson(rule)) ACache.get(cacheDir = false).put(ruleFileName, GSON.toJson(rule))
} }
fun delConfigRule() { fun delConfig() {
ACache.get(cacheDir = false).remove(ruleFileName) ACache.get(cacheDir = false).remove(ruleFileName)
} }
fun getSummary(): String? { fun getSummary(): String? {
return getConfigRule()?.summary return getRule()?.summary
} }
data class Rule( data class Rule(

@ -94,7 +94,7 @@ object Backup {
FileUtils.createFileIfNotExist(backupPath + File.separator + ThemeConfig.configFileName) FileUtils.createFileIfNotExist(backupPath + File.separator + ThemeConfig.configFileName)
.writeText(it) .writeText(it)
} }
DirectLinkUpload.getConfigRule()?.let { DirectLinkUpload.getConfig()?.let {
FileUtils.createFileIfNotExist(backupPath + File.separator + DirectLinkUpload.ruleFileName) FileUtils.createFileIfNotExist(backupPath + File.separator + DirectLinkUpload.ruleFileName)
.writeText(GSON.toJson(it)) .writeText(GSON.toJson(it))
} }

@ -24,7 +24,7 @@ class DirectLinkUploadConfig : BaseDialogFragment(R.layout.dialog_direct_link_up
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
binding.toolBar.setBackgroundColor(primaryColor) binding.toolBar.setBackgroundColor(primaryColor)
DirectLinkUpload.getConfigRule()?.let { DirectLinkUpload.getRule()?.let {
binding.editUploadUrl.setText(it.uploadUrl) binding.editUploadUrl.setText(it.uploadUrl)
binding.editDownloadUrlRule.setText(it.downloadUrlRule) binding.editDownloadUrlRule.setText(it.downloadUrlRule)
binding.editSummary.setText(it.summary) binding.editSummary.setText(it.summary)
@ -33,7 +33,7 @@ class DirectLinkUploadConfig : BaseDialogFragment(R.layout.dialog_direct_link_up
dismiss() dismiss()
} }
binding.tvFooterLeft.onClick { binding.tvFooterLeft.onClick {
DirectLinkUpload.delConfigRule() DirectLinkUpload.delConfig()
dismiss() dismiss()
} }
binding.tvOk.onClick { binding.tvOk.onClick {
@ -48,7 +48,7 @@ class DirectLinkUploadConfig : BaseDialogFragment(R.layout.dialog_direct_link_up
toastOnUi("下载Url规则不能为空") toastOnUi("下载Url规则不能为空")
return@onClick return@onClick
} }
DirectLinkUpload.putConfigRule(uploadUrl, downloadUrlRule, summary) DirectLinkUpload.putConfig(uploadUrl, downloadUrlRule, summary)
dismiss() dismiss()
} }
} }

Loading…
Cancel
Save