Commit 8800de17 authored by yanzg's avatar yanzg

表结构修改

parent e713977a
...@@ -37,7 +37,7 @@ public class FileHelper { ...@@ -37,7 +37,7 @@ public class FileHelper {
String contentType = Files.probeContentType(path); String contentType = Files.probeContentType(path);
return contentType; return contentType;
} catch (Exception ex) { } catch (Exception ex) {
throw YzgError.getRuntimeException(ex,"044",filePath); throw YzgError.getRuntimeException(ex, "044", filePath);
} }
} }
...@@ -51,7 +51,7 @@ public class FileHelper { ...@@ -51,7 +51,7 @@ public class FileHelper {
public static int getMediaType(String file) { public static int getMediaType(String file) {
String mimeType = FileHelper.getMimeType(file); String mimeType = FileHelper.getMimeType(file);
if (mimeType == null) { if (mimeType == null) {
throw YzgError.getRuntimeException("008",file); throw YzgError.getRuntimeException("008", file);
} }
int type = getMediaTypeByMime(mimeType); int type = getMediaTypeByMime(mimeType);
// System.out.println(mimeType); // System.out.println(mimeType);
...@@ -102,7 +102,7 @@ public class FileHelper { ...@@ -102,7 +102,7 @@ public class FileHelper {
if (file.isDirectory()) { if (file.isDirectory()) {
return StringHelper.EMPTY; return StringHelper.EMPTY;
} else { } else {
throw YzgError.getRuntimeException("010",file.getName()); throw YzgError.getRuntimeException("010", file.getName());
} }
} }
file.mkdirs(); file.mkdirs();
...@@ -220,11 +220,11 @@ public class FileHelper { ...@@ -220,11 +220,11 @@ public class FileHelper {
// 删除文件 // 删除文件
if (file.exists()) { if (file.exists()) {
if (!file.delete()) { if (!file.delete()) {
throw YzgError.getRuntimeException("012",file.getName()); throw YzgError.getRuntimeException("012", file.getName());
} }
} }
if (file.exists()) { if (file.exists()) {
throw YzgError.getRuntimeException("012",file.getName()); throw YzgError.getRuntimeException("012", file.getName());
} }
writeFileAppend(file, content, encoding); writeFileAppend(file, content, encoding);
} catch (RuntimeException e) { } catch (RuntimeException e) {
...@@ -322,4 +322,21 @@ public class FileHelper { ...@@ -322,4 +322,21 @@ public class FileHelper {
//删除当前目录 //删除当前目录
return dirFile.delete(); return dirFile.delete();
} }
/**
* 检查文件和文件路径
*
* @param folderFrom 文件路径
* @return 文件合法路径
*/
public static String checkFolder(String folderFrom) {
String folder = StringHelper.getFirst(folderFrom, "temp");
if (folder.contains("..")) {
throw YzgError.getRuntimeException("075");
}
if (folder.contains("\\u")) {
throw YzgError.getRuntimeException("076");
}
return folder;
}
} }
...@@ -4,6 +4,7 @@ package com.yanzuoguang.cloud.excel; ...@@ -4,6 +4,7 @@ package com.yanzuoguang.cloud.excel;
import com.yanzuoguang.cloud.helper.HttpFileHelper; import com.yanzuoguang.cloud.helper.HttpFileHelper;
import com.yanzuoguang.excel.*; import com.yanzuoguang.excel.*;
import com.yanzuoguang.util.YzgError; import com.yanzuoguang.util.YzgError;
import com.yanzuoguang.util.helper.FileHelper;
import com.yanzuoguang.util.helper.StringHelper; import com.yanzuoguang.util.helper.StringHelper;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
...@@ -95,6 +96,10 @@ public class ExcelHttp<T extends Object> extends ExcelConsole<T> { ...@@ -95,6 +96,10 @@ public class ExcelHttp<T extends Object> extends ExcelConsole<T> {
config.setDownFileName(String.format("%s-%s.xlsx", config.getTitle(), config.getSubTitle())); config.setDownFileName(String.format("%s-%s.xlsx", config.getTitle(), config.getSubTitle()));
} }
FileHelper.checkFolder(config.getServerPath());
FileHelper.checkFolder(config.getFileName());
FileHelper.checkFolder(config.getDownFileName());
ExcelHttp<M> excel = new ExcelHttp<>(config, excelStatus); ExcelHttp<M> excel = new ExcelHttp<>(config, excelStatus);
// 普通模式生成文件并下载 // 普通模式生成文件并下载
releaseExcel(req, excelDao, excel); releaseExcel(req, excelDao, excel);
......
...@@ -30,6 +30,8 @@ import java.util.Date; ...@@ -30,6 +30,8 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import static com.yanzuoguang.util.helper.FileHelper.checkFolder;
/** /**
* 文件上传服务实现 * 文件上传服务实现
* *
...@@ -457,15 +459,4 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa ...@@ -457,15 +459,4 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa
req.setTo(StringHelper.EMPTY); req.setTo(StringHelper.EMPTY);
} }
} }
private String checkFolder(String folderFrom) {
String folder = StringHelper.getFirst(folderFrom, "temp");
if (folder.contains("..")) {
throw YzgError.getRuntimeException("075");
}
if (folder.contains("\\u")) {
throw YzgError.getRuntimeException("076");
}
return folder;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment