|
@@ -3,7 +3,10 @@ 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.security.util.AuthUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
@@ -84,7 +87,7 @@ public class MyFileUtils {
|
|
|
}
|
|
|
|
|
|
public static String getAuthFilePath(String basePath, String fileName, boolean auth) {
|
|
|
- if (StringUtils.isBlank(basePath)||StringUtils.isBlank(fileName)) return "";
|
|
|
+ if (StringUtils.isBlank(basePath) || StringUtils.isBlank(fileName)) return "";
|
|
|
String resultPath = basePath + UploadConfig.SEPARATOR + fileName;
|
|
|
File file = new File(resultPath);
|
|
|
if (file.exists()) {
|
|
@@ -98,31 +101,45 @@ public class MyFileUtils {
|
|
|
return "";
|
|
|
}
|
|
|
|
|
|
- public static List<String> getSonPaths(String basePath, boolean auth) {
|
|
|
+ public static List<BFile> getSonPaths(String basePath, boolean auth) {
|
|
|
return getSonPaths(basePath, null, auth);
|
|
|
}
|
|
|
|
|
|
- public static List<String> getSonPaths(String basePath, FilenameFilter filter, boolean auth) {
|
|
|
+ public static List<BFile> getSonPaths(String basePath, FilenameFilter filter, boolean auth) {
|
|
|
if (StringUtils.isBlank(basePath)) return Lists.newArrayList();
|
|
|
File file = new File(basePath);
|
|
|
if (file.exists() && file.isDirectory()) {
|
|
|
- String[] sonStrs = filter == null ? file.list() : file.list(filter);
|
|
|
- if (sonStrs == null) return Lists.newArrayList();
|
|
|
- return Arrays.stream(sonStrs)
|
|
|
- .filter(son -> auth || !son.contains("~"))
|
|
|
- .map(son -> basePath + UploadConfig.SEPARATOR + son)
|
|
|
+ File[] sonFiles = filter == null ? file.listFiles() : file.listFiles(filter);
|
|
|
+ if (sonFiles == null) return Lists.newArrayList();
|
|
|
+ return Arrays.stream(sonFiles)
|
|
|
+ .filter(son -> auth || !son.getName().startsWith("~"))
|
|
|
+ .map(son -> {
|
|
|
+ final BFile sonFile = new BFile();
|
|
|
+ sonFile.setName(son.getName());
|
|
|
+ sonFile.setPath(son.getPath());
|
|
|
+ sonFile.setIsDirectory(son.isDirectory() ? 1 : 0);
|
|
|
+ return sonFile;
|
|
|
+ })
|
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
|
return Lists.newArrayList();
|
|
|
}
|
|
|
|
|
|
- public static void main(String[] args) {
|
|
|
- String path = "F:/StudyWorkSpace/doc-manager/power";
|
|
|
- final BDirectory file = getAllAuthDirectory(new File(path), true);
|
|
|
- System.out.println(file);
|
|
|
+ /**
|
|
|
+ *@describe 获取根目录下的所有文件夹
|
|
|
+ *@param userDetails
|
|
|
+ *@return com.macro.mall.tiny.modules.business.model.BDirectory
|
|
|
+ *@author gjs
|
|
|
+ *@since J7.23.0
|
|
|
+ *@date 2021/4/2
|
|
|
+ */
|
|
|
+ public static BDirectory getRootDirectory(AdminUserDetails userDetails) {
|
|
|
+ final boolean access = AuthUtil.checkAccess(userDetails, "/visit");
|
|
|
+ final File rootDirectory = new File(UploadConfig.powerPath);
|
|
|
+ return getAllAuthDirectory(rootDirectory, access);
|
|
|
}
|
|
|
|
|
|
- public static BDirectory getAllAuthDirectory(File file, boolean auth) {
|
|
|
+ public static BDirectory getAllAuthDirectory(File file, boolean access) {
|
|
|
if (!file.exists() && !file.isDirectory()) {
|
|
|
return null;
|
|
|
}
|
|
@@ -130,13 +147,13 @@ public class MyFileUtils {
|
|
|
List<BDirectory> subDirectory = Lists.newArrayList();
|
|
|
boolean hasFile = false;
|
|
|
|
|
|
- final File[] subFiles = file.listFiles((dir, name) -> auth || !name.startsWith(String.valueOf(UploadConfig.AUTH_STR)));
|
|
|
+ final File[] subFiles = file.listFiles((dir, name) -> access || !name.startsWith(String.valueOf(UploadConfig.AUTH_STR)));
|
|
|
if (subFiles != null && subFiles.length > 0) {
|
|
|
for (File subFile : subFiles) {
|
|
|
if (!subFile.isDirectory() && !hasFile) {
|
|
|
hasFile = true;
|
|
|
- } else {
|
|
|
- subDirectory.add(getAllAuthDirectory(subFile, auth));
|
|
|
+ } else if (subFile.isDirectory()) {
|
|
|
+ subDirectory.add(getAllAuthDirectory(subFile, access));
|
|
|
}
|
|
|
}
|
|
|
}
|