优化
This commit is contained in:
@@ -1,5 +1,12 @@
|
|||||||
{
|
[
|
||||||
"uploadUrl": "https://sy.mgz6.cc/shuyuan,{\"method\":\"POST\",\"body\": {\"file\": \"fileRequest\"},\"type\": \"multipart/form-data\"}",
|
{
|
||||||
"downloadUrlRule": "$.data@js:if (result == '') \n '' \n else \n 'https://shuyuan.mgz6.cc/shuyuan/' + result",
|
"uploadUrl": "https://sy.mgz6.cc/shuyuan,{\"method\":\"POST\",\"body\": {\"file\": \"fileRequest\"},\"type\": \"multipart/form-data\"}",
|
||||||
"summary": "有效期2天"
|
"downloadUrlRule": "$.data@js:if (result == '') \n '' \n else \n 'https://shuyuan.mgz6.cc/shuyuan/' + result",
|
||||||
}
|
"summary": "喵公子网盘(有效期2天)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"uploadUrl": "http://v2.jt12.de/up-v2.php,{\"method\":\"POST\",\"body\": {\"file\": \"fileRequest\"},\"type\": \"multipart/form-data\"}",
|
||||||
|
"downloadUrlRule": "$.msg",
|
||||||
|
"summary": "橘途网盘(永久有效)"
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -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? {
|
fun getRule(): Rule {
|
||||||
return getConfig() ?: defaultRule
|
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
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ object UrlUtil {
|
|||||||
*/
|
*/
|
||||||
fun getFileName(fileUrl: String): String? {
|
fun getFileName(fileUrl: String): String? {
|
||||||
return kotlin.runCatching {
|
return kotlin.runCatching {
|
||||||
var fileName = ""
|
var fileName: String
|
||||||
val url = URL(fileUrl)
|
val url = URL(fileUrl)
|
||||||
val conn: HttpURLConnection = url.openConnection() as HttpURLConnection
|
val conn: HttpURLConnection = url.openConnection() as HttpURLConnection
|
||||||
// head方式
|
// head方式
|
||||||
@@ -63,7 +63,7 @@ object UrlUtil {
|
|||||||
fun getSuffix(url: String, default: String): String {
|
fun getSuffix(url: String, default: String): String {
|
||||||
val suffix = url.substringAfterLast(".").substringBeforeLast(",")
|
val suffix = url.substringAfterLast(".").substringBeforeLast(",")
|
||||||
//检查截取的后缀字符是否合法 [a-zA-Z0-9]
|
//检查截取的后缀字符是否合法 [a-zA-Z0-9]
|
||||||
val fileSuffixRegex = Regex("^[a-z0-9]+$", RegexOption.IGNORE_CASE)
|
val fileSuffixRegex = Regex("^[a-z\\d]+$", RegexOption.IGNORE_CASE)
|
||||||
return if (suffix.length > 5 || !suffix.matches(fileSuffixRegex)) {
|
return if (suffix.length > 5 || !suffix.matches(fileSuffixRegex)) {
|
||||||
default
|
default
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user