mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-09 20:57:21 +08:00
feat(system/file): 文件管理呈目录形式展示 (#151)
This commit is contained in:
@@ -56,7 +56,7 @@ public class FileRecorderImpl implements FileRecorder {
|
||||
|
||||
/**
|
||||
* 文件信息存储
|
||||
*
|
||||
*
|
||||
* @param fileInfo 文件信息对象
|
||||
* @return 是否保存成功
|
||||
*/
|
||||
@@ -71,27 +71,25 @@ public class FileRecorderImpl implements FileRecorder {
|
||||
? StrUtil.subBefore(originalFilename, StringConstants.DOT, true)
|
||||
: originalFilename);
|
||||
StorageDO storage = (StorageDO)fileInfo.getAttr().get(ClassUtil.getClassName(StorageDO.class, false));
|
||||
String domain = StrUtil.appendIfMissing(storage.getDomain(), StringConstants.SLASH);
|
||||
String filePath = StrUtil.appendIfMissing(fileInfo.getPath(), StringConstants.SLASH);
|
||||
// 处理fileInfo中存储的地址
|
||||
fileInfo.setUrl(URLUtil.normalize(domain + fileInfo.getPath() + fileInfo.getFilename()));
|
||||
fileInfo.setThUrl(URLUtil.normalize(domain + fileInfo.getPath() + fileInfo.getThFilename()));
|
||||
fileInfo.setUrl(URLUtil.normalize(storage.getDomain() + filePath + fileInfo.getFilename()));
|
||||
fileInfo.setThUrl(URLUtil.normalize(storage.getDomain() + filePath + fileInfo.getThFilename()));
|
||||
file.setUrl(fileInfo.getUrl());
|
||||
file.setSize(fileInfo.getSize());
|
||||
String absPath = fileInfo.getPath();
|
||||
if (absPath.endsWith(StringConstants.SLASH)) {
|
||||
String tempAbsPath = absPath.substring(0, absPath.length() - 1);
|
||||
String[] pathArr = tempAbsPath.split(StringConstants.SLASH);
|
||||
if (pathArr.length > 1) {
|
||||
file.setParentPath(pathArr[pathArr.length - 1]);
|
||||
} else {
|
||||
file.setParentPath(StringConstants.SLASH);
|
||||
}
|
||||
String tempAbsPath = absPath.length() > 1 ? StrUtil.removeSuffix(absPath, StringConstants.SLASH) : absPath;
|
||||
String[] pathArr = tempAbsPath.split(StringConstants.SLASH);
|
||||
if (pathArr.length > 1) {
|
||||
file.setParentPath(pathArr[pathArr.length - 1]);
|
||||
} else {
|
||||
file.setParentPath(StringConstants.SLASH);
|
||||
}
|
||||
file.setAbsPath(fileInfo.getPath());
|
||||
file.setAbsPath(tempAbsPath);
|
||||
file.setExtension(fileInfo.getExt());
|
||||
file.setType(FileTypeEnum.getByExtension(file.getExtension()));
|
||||
file.setContentType(fileInfo.getContentType());
|
||||
file.setMd5(fileInfo.getHashInfo().getMd5());
|
||||
file.setMd5(fileInfo.getHashInfo().getSha256());
|
||||
file.setMetadata(JSONUtil.toJsonStr(fileInfo.getMetadata()));
|
||||
file.setThumbnailUrl(fileInfo.getThUrl());
|
||||
file.setThumbnailSize(fileInfo.getThSize());
|
||||
|
@@ -44,4 +44,10 @@ public class FileReq implements Serializable {
|
||||
@NotBlank(message = "文件名称不能为空")
|
||||
@Length(max = 255, message = "文件名称长度不能超过 {max} 个字符")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 上级目录
|
||||
*/
|
||||
@Schema(description = "上级目录", example = "25")
|
||||
private String parentPath;
|
||||
}
|
@@ -25,6 +25,7 @@ import top.continew.admin.system.model.resp.file.FileResp;
|
||||
import top.continew.admin.system.model.resp.file.FileStatisticsResp;
|
||||
import top.continew.starter.core.constant.StringConstants;
|
||||
import top.continew.starter.data.mp.service.IService;
|
||||
import top.continew.starter.extension.crud.model.resp.IdResp;
|
||||
import top.continew.starter.extension.crud.service.BaseService;
|
||||
|
||||
import java.time.LocalDate;
|
||||
@@ -94,4 +95,8 @@ public interface FileService extends BaseService<FileResp, FileResp, FileQuery,
|
||||
return today.getYear() + StringConstants.SLASH + today.getMonthValue() + StringConstants.SLASH + today
|
||||
.getDayOfMonth() + StringConstants.SLASH;
|
||||
}
|
||||
|
||||
FileResp check(String fileHash);
|
||||
|
||||
IdResp<Long> createDir(FileReq req);
|
||||
}
|
@@ -44,6 +44,7 @@ import top.continew.starter.core.constant.StringConstants;
|
||||
import top.continew.starter.core.util.StrUtils;
|
||||
import top.continew.starter.core.util.URLUtils;
|
||||
import top.continew.starter.core.validation.CheckUtils;
|
||||
import top.continew.starter.extension.crud.model.resp.IdResp;
|
||||
import top.continew.starter.extension.crud.service.BaseServiceImpl;
|
||||
|
||||
import java.util.List;
|
||||
@@ -91,7 +92,9 @@ public class FileServiceImpl extends BaseServiceImpl<FileMapper, FileDO, FileRes
|
||||
UploadPretreatment uploadPretreatment = fileStorageService.of(file)
|
||||
.setPlatform(storage.getCode())
|
||||
.setHashCalculatorMd5(true)
|
||||
.setHashCalculatorSha256(true)
|
||||
.putAttr(ClassUtil.getClassName(StorageDO.class, false), storage)
|
||||
// .setPath(StrUtil.removePrefix(path, StringConstants.SLASH));
|
||||
.setPath(path);
|
||||
// 图片文件生成缩略图
|
||||
if (FileTypeEnum.IMAGE.getExtensions().contains(FileNameUtil.extName(file.getOriginalFilename()))) {
|
||||
@@ -138,6 +141,40 @@ public class FileServiceImpl extends BaseServiceImpl<FileMapper, FileDO, FileRes
|
||||
return resp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileResp check(String fileHash) {
|
||||
FileDO file = baseMapper.lambdaQuery().eq(FileDO::getMd5, fileHash).one();
|
||||
if (file != null) {
|
||||
return get(file.getId());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdResp<Long> createDir(FileReq req) {
|
||||
StorageDO storage = storageService.getDefaultStorage();
|
||||
FileDO fileDo = new FileDO();
|
||||
fileDo.setName(req.getName());
|
||||
fileDo.setSize(0L);
|
||||
fileDo.setUrl(storage.getDomain() + req.getParentPath() + req.getName());
|
||||
String absPath = req.getParentPath();
|
||||
String tempAbsPath = absPath.length() > 1 ? StrUtil.removeSuffix(absPath, StringConstants.SLASH) : absPath;
|
||||
String[] pathArr = tempAbsPath.split(StringConstants.SLASH);
|
||||
if (pathArr.length > 1) {
|
||||
fileDo.setParentPath(pathArr[pathArr.length - 1]);
|
||||
} else {
|
||||
fileDo.setParentPath(StringConstants.SLASH);
|
||||
}
|
||||
fileDo.setAbsPath(tempAbsPath);
|
||||
fileDo.setExtension("dir");
|
||||
fileDo.setContentType("");
|
||||
fileDo.setType(FileTypeEnum.DIR);
|
||||
fileDo.setMd5("");
|
||||
fileDo.setStorageId(storage.getId());
|
||||
baseMapper.insert(fileDo);
|
||||
return new IdResp<>(fileDo.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fill(Object obj) {
|
||||
super.fill(obj);
|
||||
|
Reference in New Issue
Block a user