return b;
}
@Override
public String download(String fileName, String userName, String path) {
// 服务器下载的文件所在的本地路径的文件夹
String saveFilePath = fileRootPath + userName + “/” + path;
logger.warn(“1 saveFilePath:” + saveFilePath);
// 判断文件夹是否存在-建立文件夹
File filePathDir = new File(saveFilePath);
if (!filePathDir.exists()) {
filePathDir.mkdir();
}
// 本地路径
saveFilePath = saveFilePath + “/” + fileName;
String link = saveFilePath.replace(fileRootPath, “/data/”);
link = StringUtil.stringSlashToOne(link);
logger.warn(“返回的路径:” + link);
return link;
}
@Override
public List userFileList(String userName, String path) {
logger.warn(“执行userFileList函数!”);
List fileMsgList = new ArrayList<>();
// 拉取文件列表-本地磁盘
String webSaveFilePath = fileRootPath + userName + “/” + path;
File files = new File(webSaveFilePath);
if (!files.exists()) {
return fileMsgList;
}
File[] tempList = files.listFiles();
if (tempList == null) {
return fileMsgList;
}
for (File file : tempList) {
if (file.isFile()) {
FileMsg fileMsg = new FileMsg();
// 获取文件名和下载地址
String link = file.toString().replace(“\”, “/”);
String[] nameArr = link.split(“/”);
String name = nameArr[nameArr.length - 1];
link = link.replace(fileRootPath, “/data/”);
link = link.replace(“/root/pan/”, “/data/”);
String size = FileUtil.fileSizeToString(file.length());
SimpleDateFormat formatter = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
String lastModTime = formatter.format(file.lastModified());
// 赋值到json
fileMsg.setName(name);
fileMsg.setLink(link);
fileMsg.setSize(size);
fileMsg.setTime(lastModTime);
if (FileUtil.isMp4(name)) {
fileMsg.setType(“mp4”);
} else if (FileUtil.isVideo(name)) {
fileMsg.setType(“video”);
} else {
fileMsg.setType(“file”);
}
fileMsgList.add(fileMsg);
} else {
FileMsg fileMsg = new FileMsg();
String link = file.toString().replace(“\”, “/”);
String[] nameArr = link.split(“/”);
String name = nameArr[nameArr.length - 1];
String dirPath = link.replace(fileRootPath + userName, “”);
if (!name.equals(“userIcon”)) {
fileMsg.setName(name);
fileMsg.setSize(“Directory”);
fileMsg.setType(“dir”);
fileMsg.setLink(dirPath);
SimpleDateFormat formatter = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”);
String lastModTime = formatter.format(file.lastModified());
fileMsg.setTime(lastModTime);
fileMsgList.add(fileMsg);
}
}
}
//排序
ListUtil.listSort(fileMsgList);
return fileMsgList;
<