|
@@ -6,6 +6,7 @@ import io.legado.app.model.analyzeRule.AnalyzeRule
|
|
|
import io.legado.app.model.analyzeRule.AnalyzeUrl
|
|
import io.legado.app.model.analyzeRule.AnalyzeUrl
|
|
|
import io.legado.app.utils.ACache
|
|
import io.legado.app.utils.ACache
|
|
|
import io.legado.app.utils.GSON
|
|
import io.legado.app.utils.GSON
|
|
|
|
|
+import io.legado.app.utils.fromJsonArray
|
|
|
import io.legado.app.utils.fromJsonObject
|
|
import io.legado.app.utils.fromJsonObject
|
|
|
import splitties.init.appCtx
|
|
import splitties.init.appCtx
|
|
|
import java.io.File
|
|
import java.io.File
|
|
@@ -18,7 +19,6 @@ 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 = getRule()
|
|
val rule = getRule()
|
|
|
- rule ?: throw NoStackTraceException("直链上传规则未配置")
|
|
|
|
|
val url = rule.uploadUrl
|
|
val url = rule.uploadUrl
|
|
|
if (url.isBlank()) {
|
|
if (url.isBlank()) {
|
|
|
throw NoStackTraceException("上传url未配置")
|
|
throw NoStackTraceException("上传url未配置")
|
|
@@ -37,16 +37,16 @@ object DirectLinkUpload {
|
|
|
return downloadUrl
|
|
return downloadUrl
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private val defaultRule: Rule? by lazy {
|
|
|
|
|
|
|
+ private val defaultRules: List<Rule> by lazy {
|
|
|
val json = String(
|
|
val json = String(
|
|
|
appCtx.assets.open("defaultData${File.separator}directLinkUpload.json")
|
|
appCtx.assets.open("defaultData${File.separator}directLinkUpload.json")
|
|
|
.readBytes()
|
|
.readBytes()
|
|
|
)
|
|
)
|
|
|
- GSON.fromJsonObject<Rule>(json).getOrNull()
|
|
|
|
|
|
|
+ GSON.fromJsonArray<Rule>(json).getOrThrow()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- fun getRule(): Rule? {
|
|
|
|
|
- return getConfig() ?: defaultRule
|
|
|
|
|
|
|
+ fun getRule(): Rule {
|
|
|
|
|
+ return getConfig() ?: defaultRules[0]
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fun getConfig(): Rule? {
|
|
fun getConfig(): Rule? {
|
|
@@ -64,7 +64,7 @@ object DirectLinkUpload {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fun getSummary(): String? {
|
|
fun getSummary(): String? {
|
|
|
- return getRule()?.summary
|
|
|
|
|
|
|
+ return getRule().summary
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Keep
|
|
@Keep
|