重构下载文件的代码,修复文件重新下载的问题 (#485)

* 重构下载文件的代码,修复文件重新下载的问题

* fix: 修复可能得空指针问题
This commit is contained in:
kl
2023-08-31 10:47:41 +08:00
committed by GitHub
parent c2abe2f34c
commit 692bb8f964
2 changed files with 33 additions and 76 deletions

View File

@@ -34,29 +34,33 @@ public class KkFileUtils {
/**
* 检查文件名是否合规
*
* @param fileName 文件名
* @return 合规结果,true:不合规false:合规
* @return 合规结果, true:不合规false:合规
*/
public static boolean isIllegalFileName(String fileName){
for (String str: illegalFileStrList){
if(fileName.contains(str)){
public static boolean isIllegalFileName(String fileName) {
for (String str : illegalFileStrList) {
if (fileName.contains(str)) {
return true;
}
}
return false;
}
/**
* 检查是否是数字
*
* @param str 文件名
* @return 合规结果,true:不合规false:合规
* @return 合规结果, true:不合规false:合规
*/
public static boolean isInteger(String str) {
if(StringUtils.hasText(str)){
if (StringUtils.hasText(str)) {
boolean strResult = str.matches("-?[0-9]+.?[0-9]*");
return strResult ;
return strResult;
}
return false;
}
/**
* 判断url是否是http资源
*
@@ -102,7 +106,7 @@ public class KkFileUtils {
public static String htmlEscape(String input) {
if(StringUtils.hasText(input)){
if (StringUtils.hasText(input)) {
//input = input.replaceAll("\\{", "%7B").replaceAll("}", "%7D").replaceAll("\\\\", "%5C");
String htmlStr = HtmlUtils.htmlEscape(input, "UTF-8");
//& -> &
@@ -186,11 +190,23 @@ public class KkFileUtils {
*/
public static boolean isAllowedUpload(String file) {
String fileType = suffixFromFileName(file);
for (String type : ConfigConstants.getProhibit()) {
if (type.equals(fileType))
for (String type : ConfigConstants.getProhibit()) {
if (type.equals(fileType)){
return false;
}
}
return !ObjectUtils.isEmpty(fileType);
}
/**
* 判断文件是否存在
*
* @param filePath 文件路径
* @return 是否存在 true:存在false:不存在
*/
public static boolean isExist(String filePath) {
File file = new File(filePath);
return file.exists();
}
}