|
@@ -3,7 +3,6 @@ package com.macro.mall.tiny.common.util;
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.macro.mall.tiny.config.UploadConfig;
|
|
|
-import com.macro.mall.tiny.domain.AdminUserDetails;
|
|
|
import com.macro.mall.tiny.modules.business.model.BDirectory;
|
|
|
import com.macro.mall.tiny.modules.business.model.BFile;
|
|
|
import com.macro.mall.tiny.modules.business.model.BFileDetail;
|
|
@@ -12,7 +11,10 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.*;
|
|
|
-import java.util.*;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.UUID;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -100,16 +102,16 @@ public class MyFileUtils {
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
- public static List<BFile> getSonFiles(String basePath) {
|
|
|
+ public static List<BFile> getSubBFiles(String basePath) {
|
|
|
boolean access = AuthUtil.checkAccess(AuthUtil.ACCESS);
|
|
|
- return getSonFiles(basePath, null, access);
|
|
|
+ return getSubBFiles(basePath, null, access);
|
|
|
}
|
|
|
|
|
|
- public static List<BFile> getSonFiles(String basePath, boolean auth) {
|
|
|
- return getSonFiles(basePath, null, auth);
|
|
|
+ public static List<BFile> getSubBFiles(String basePath, boolean auth) {
|
|
|
+ return getSubBFiles(basePath, null, auth);
|
|
|
}
|
|
|
|
|
|
- public static List<BFile> getSonFiles(String basePath, FilenameFilter filter, boolean auth) {
|
|
|
+ public static List<BFile> getSubBFiles(String basePath, FilenameFilter filter, boolean auth) {
|
|
|
if (StringUtils.isBlank(basePath)) return Lists.newArrayList();
|
|
|
File oriDic = new File(basePath);
|
|
|
if (!oriDic.exists() || oriDic.isFile() || (!auth && basePath.contains(String.valueOf(UploadConfig.AUTH_STR)))) {
|
|
@@ -125,7 +127,7 @@ public class MyFileUtils {
|
|
|
sonFile.setPath(son.getPath());
|
|
|
sonFile.setIsDirectory(son.isDirectory() ? 1 : 0);
|
|
|
if (son.isDirectory()) {
|
|
|
- sonFile.setSubFile(getSonFiles(son.getPath(), filter, auth));
|
|
|
+ sonFile.setSubFile(getSubBFiles(son.getPath(), filter, auth));
|
|
|
}
|
|
|
return sonFile;
|
|
|
})
|
|
@@ -155,7 +157,7 @@ public class MyFileUtils {
|
|
|
List<BDirectory> subDirectory = null;
|
|
|
boolean hasFile = false;
|
|
|
|
|
|
- final File[] subFiles = file.listFiles((dir, name) -> access || !name.startsWith(String.valueOf(UploadConfig.AUTH_STR)));
|
|
|
+ final File[] subFiles = getSubBFiles(file, access);
|
|
|
if (subFiles != null && subFiles.length > 0) {
|
|
|
for (File subFile : subFiles) {
|
|
|
if (subFile.isFile()) {
|
|
@@ -184,7 +186,7 @@ public class MyFileUtils {
|
|
|
if (!oriDic.exists() || oriDic.isFile() || (!access && path.contains(String.valueOf(UploadConfig.AUTH_STR)))) {
|
|
|
return Lists.newArrayList();
|
|
|
}
|
|
|
- File[] subFiles = oriDic.listFiles((dir, name) -> access || !name.startsWith(String.valueOf(UploadConfig.AUTH_STR)));
|
|
|
+ File[] subFiles = getSubBFiles(oriDic, access);
|
|
|
if (subFiles == null) return Lists.newArrayList();
|
|
|
return Arrays.stream(subFiles)
|
|
|
.filter(File::isFile)
|
|
@@ -232,7 +234,7 @@ public class MyFileUtils {
|
|
|
if (!dic.exists() || !dic.isDirectory()) {
|
|
|
return false;
|
|
|
}
|
|
|
- File[] subFiles = filter == null ? dic.listFiles((dir, name) -> access || !name.startsWith(String.valueOf(UploadConfig.AUTH_STR))) : dic.listFiles(filter);
|
|
|
+ File[] subFiles = filter == null ? getSubBFiles(dic, access) : dic.listFiles(filter);
|
|
|
if (subFiles == null) {
|
|
|
return false;
|
|
|
}
|
|
@@ -248,7 +250,7 @@ public class MyFileUtils {
|
|
|
if (!directory.exists() || !directory.isDirectory()) {
|
|
|
return;
|
|
|
}
|
|
|
- File[] subFiles = directory.listFiles((dir, name) -> access || !name.startsWith(String.valueOf(UploadConfig.AUTH_STR)));
|
|
|
+ File[] subFiles = getSubBFiles(directory, access);
|
|
|
if (subFiles == null) {
|
|
|
return;
|
|
|
}
|
|
@@ -260,4 +262,8 @@ public class MyFileUtils {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ private static File[] getSubBFiles(File directory, boolean access) {
|
|
|
+ return directory.listFiles((dir, name) -> access || !name.startsWith(String.valueOf(UploadConfig.AUTH_STR)));
|
|
|
+ }
|
|
|
}
|