mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
[skip ci] add UrlUtil.getSuffix
This commit is contained in:
@@ -178,13 +178,7 @@ object BookHelp {
|
||||
}
|
||||
|
||||
fun getImageSuffix(src: String): String {
|
||||
var suffix = src.substringAfterLast(".").substringBefore(",")
|
||||
//检查截取的后缀字符是否合法 [a-zA-Z0-9]
|
||||
val fileSuffixRegex = Regex("^[a-z0-9]+$", RegexOption.IGNORE_CASE)
|
||||
if (suffix.length > 5 || !suffix.matches(fileSuffixRegex)) {
|
||||
suffix = "jpg"
|
||||
}
|
||||
return suffix
|
||||
return UrlUtil.getSuffix(src, "jpg")
|
||||
}
|
||||
|
||||
@Throws(IOException::class, FileNotFoundException::class)
|
||||
|
||||
@@ -266,16 +266,9 @@ object LocalBook {
|
||||
|
||||
/**
|
||||
* 分析下载文件类书源的下载链接的文件后缀
|
||||
* https://www.example.com/download/{fileName}.{type} 含有文件名和后缀
|
||||
* https://www.example.com/download/?fileid=1234, {type: "txt"} 规则设置
|
||||
*/
|
||||
fun parseFileSuffix(url: String): String {
|
||||
val analyzeUrl = AnalyzeUrl(url)
|
||||
val urlNoOption = analyzeUrl.url
|
||||
val lastPath = urlNoOption.substringAfterLast("/")
|
||||
val fileType = lastPath.substringAfterLast(".")
|
||||
val type = analyzeUrl.type
|
||||
return type ?: fileType
|
||||
return UrlUtil.getSuffix(url, "ext")
|
||||
}
|
||||
|
||||
fun saveBookFile(
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package io.legado.app.utils
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
object UrlUtil {
|
||||
|
||||
fun replaceReservedChar(text: String): String {
|
||||
@@ -24,5 +26,15 @@ object UrlUtil {
|
||||
.replace("|", "%7C")
|
||||
}
|
||||
|
||||
fun getSuffix(url: String, default: String): String {
|
||||
val suffix = url.ubstringAfterLast(".").substringBeforeLast(",")
|
||||
//检查截取的后缀字符是否合法 [a-zA-Z0-9]
|
||||
val fileSuffixRegex = Regex("^[a-z0-9]+$", RegexOption.IGNORE_CASE)
|
||||
return if (suffix.length > 5 || !suffix.matches(fileSuffixRegex)) {
|
||||
default
|
||||
} else {
|
||||
suffix
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user