Commit 70c279f8 authored by yanzg's avatar yanzg

文件处理

parent 60bb73d0
...@@ -43,14 +43,7 @@ public class YzgFileServiceImpl implements YzgFileService { ...@@ -43,14 +43,7 @@ public class YzgFileServiceImpl implements YzgFileService {
if (req.getFile() == null || req.getFile().length == 0) { if (req.getFile() == null || req.getFile().length == 0) {
throw new CodeException("请上传文件"); throw new CodeException("请上传文件");
} }
String folder = StringHelper.getFirst(req.getFolder(), "temp"); String folder = getTempFolder(req.getFolder());
if (folder.contains("..")) {
throw new CodeException("文件夹不能包含两个.");
}
if (folder.contains("\\u")) {
throw new CodeException("文件夹不能包含\\u");
}
for (MultipartFile uploadFile : req.getFile()) { for (MultipartFile uploadFile : req.getFile()) {
// 获取上传源文件名和扩展名 // 获取上传源文件名和扩展名
String originalFilename = uploadFile.getOriginalFilename(); String originalFilename = uploadFile.getOriginalFilename();
...@@ -91,6 +84,7 @@ public class YzgFileServiceImpl implements YzgFileService { ...@@ -91,6 +84,7 @@ public class YzgFileServiceImpl implements YzgFileService {
*/ */
@Override @Override
public void removeTempFolder(String tempFolder) { public void removeTempFolder(String tempFolder) {
tempFolder = getTempFolder(tempFolder);
// 设置标记 // 设置标记
synchronized (cacheRemoveTempFolder) { synchronized (cacheRemoveTempFolder) {
if (StringHelper.toBoolean(cacheRemoveTempFolder.get(tempFolder))) { if (StringHelper.toBoolean(cacheRemoveTempFolder.get(tempFolder))) {
...@@ -98,7 +92,6 @@ public class YzgFileServiceImpl implements YzgFileService { ...@@ -98,7 +92,6 @@ public class YzgFileServiceImpl implements YzgFileService {
} }
cacheRemoveTempFolder.put(tempFolder, true); cacheRemoveTempFolder.put(tempFolder, true);
} }
try { try {
// 删除当前临时目录 // 删除当前临时目录
FileHelper.deleteFolder(tempFolder); FileHelper.deleteFolder(tempFolder);
...@@ -127,4 +120,16 @@ public class YzgFileServiceImpl implements YzgFileService { ...@@ -127,4 +120,16 @@ public class YzgFileServiceImpl implements YzgFileService {
); );
return ret; return ret;
} }
private String checkFolder(String folderFrom) {
String folder = StringHelper.getFirst(folderFrom, "temp");
if (folder.contains("..")) {
throw new CodeException("文件夹不能包含两个.");
}
if (folder.contains("\\u")) {
throw new CodeException("文件夹不能包含\\u");
}
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