This commit is contained in:
kunfei
2023-03-15 19:42:43 +08:00
parent 0c57ca881d
commit e8db1cb25d
3 changed files with 20 additions and 13 deletions

View File

@@ -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",
"summary": "有效期2天"
}
[
{
"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",
"summary": "喵公子网盘(有效期2天)"
},
{
"uploadUrl": "http://v2.jt12.de/up-v2.php,{\"method\":\"POST\",\"body\": {\"file\": \"fileRequest\"},\"type\": \"multipart/form-data\"}",
"downloadUrlRule": "$.msg",
"summary": "橘途网盘(永久有效)"
}
]

View File

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

View File

@@ -34,7 +34,7 @@ object UrlUtil {
*/
fun getFileName(fileUrl: String): String? {
return kotlin.runCatching {
var fileName = ""
var fileName: String
val url = URL(fileUrl)
val conn: HttpURLConnection = url.openConnection() as HttpURLConnection
// head方式
@@ -63,7 +63,7 @@ object UrlUtil {
fun getSuffix(url: String, default: String): String {
val suffix = url.substringAfterLast(".").substringBeforeLast(",")
//检查截取的后缀字符是否合法 [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)) {
default
} else {