fix(js/java.cacheFile): 下载出错时保存类出错信息
This commit is contained in:
@@ -195,16 +195,17 @@ interface JsExtensions : JsEncodeUtils {
|
|||||||
* 缓存以文本方式保存的文件 如.js .txt等
|
* 缓存以文本方式保存的文件 如.js .txt等
|
||||||
* @param saveTime 缓存时间,单位:秒
|
* @param saveTime 缓存时间,单位:秒
|
||||||
*/
|
*/
|
||||||
fun cacheFile(urlStr: String, saveTime: Int): String? {
|
fun cacheFile(urlStr: String, saveTime: Int): String {
|
||||||
val key = md5Encode16(urlStr)
|
val key = md5Encode16(urlStr)
|
||||||
val cache = CacheManager.getFile(key)
|
val cahcePath = CacheManager.get(key)
|
||||||
if (cache.isNullOrBlank()) {
|
return if (cache.isNullOrBlank()) {
|
||||||
log("首次下载 $urlStr")
|
val path = downloadFile(urlStr)
|
||||||
val value = ajax(urlStr) ?: return null
|
log("首次下载 $urlStr >> $path")
|
||||||
CacheManager.putFile(key, value, saveTime)
|
CacheManager.put(key, path, saveTime)
|
||||||
return value
|
readTxtFile(path)
|
||||||
|
} else {
|
||||||
|
readTxtFile(cahcePath)
|
||||||
}
|
}
|
||||||
return cache
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -224,12 +225,12 @@ interface JsExtensions : JsEncodeUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 下载文件
|
* 下载文件
|
||||||
* @param url 下载地址:可带参数type,文件后缀,不带默认zip
|
* @param url 下载地址:可带参数type
|
||||||
* @return 下载的文件相对路径
|
* @return 下载的文件相对路径
|
||||||
*/
|
*/
|
||||||
fun downloadFile(url: String): String {
|
fun downloadFile(url: String): String {
|
||||||
val analyzeUrl = AnalyzeUrl(url, source = getSource())
|
val analyzeUrl = AnalyzeUrl(url, source = getSource())
|
||||||
val type = analyzeUrl.type ?: "zip"
|
val type = UrlUtil.getSuffix(url, analyzeUrl.type)
|
||||||
val path = FileUtils.getPath(
|
val path = FileUtils.getPath(
|
||||||
File(FileUtils.getCachePath()),
|
File(FileUtils.getCachePath()),
|
||||||
"${MD5Utils.md5Encode16(url)}.${type}"
|
"${MD5Utils.md5Encode16(url)}.${type}"
|
||||||
@@ -250,6 +251,10 @@ interface JsExtensions : JsEncodeUtils {
|
|||||||
* @param url 通过url里的参数来判断文件类型
|
* @param url 通过url里的参数来判断文件类型
|
||||||
* @return 相对路径
|
* @return 相对路径
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(
|
||||||
|
"Depreted",
|
||||||
|
ReplaceWith("downloadFile(url: String)")
|
||||||
|
)
|
||||||
fun downloadFile(content: String, url: String): String {
|
fun downloadFile(content: String, url: String): String {
|
||||||
val type = AnalyzeUrl(url, source = getSource()).type ?: return ""
|
val type = AnalyzeUrl(url, source = getSource()).type ?: return ""
|
||||||
val path = FileUtils.getPath(
|
val path = FileUtils.getPath(
|
||||||
|
|||||||
@@ -142,6 +142,7 @@ object UrlUtil {
|
|||||||
) {
|
) {
|
||||||
path.substringAfterLast("/")
|
path.substringAfterLast("/")
|
||||||
} else {
|
} else {
|
||||||
|
AppLog.put("getFileNameFromPath: Unexpected file suffix: $suffix")
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user