添加获取指定路径文件信息的 API

This commit is contained in:
zhaojun1998
2020-01-28 14:55:06 +08:00
parent 38b811f8e6
commit b6a2e3ccb8
8 changed files with 91 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
package im.zhaojun.local.service;
import cn.hutool.core.util.URLUtil;
import im.zhaojun.common.exception.NotExistFileException;
import im.zhaojun.common.model.StorageConfig;
import im.zhaojun.common.model.SystemConfig;
import im.zhaojun.common.model.constant.StorageConfigConstant;
@@ -105,4 +106,26 @@ public class LocalServiceImpl extends AbstractFileService implements FileService
return StorageTypeEnum.LOCAL;
}
@Override
public FileItemDTO getFileItem(String path) {
String fullPath = StringUtils.concatPath(filePath, path);
File file = new File(fullPath);
if (!file.exists()) {
throw new NotExistFileException();
}
FileItemDTO fileItemDTO = new FileItemDTO();
fileItemDTO.setType(file.isDirectory() ? FileTypeEnum.FOLDER : FileTypeEnum.FILE);
fileItemDTO.setTime(new Date(file.lastModified()));
fileItemDTO.setSize(file.length());
fileItemDTO.setName(file.getName());
fileItemDTO.setPath(filePath);
if (file.isFile()) {
fileItemDTO.setUrl(getDownloadUrl(path));
}
return fileItemDTO;
}
}