mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
上传文件增加路径解析
This commit is contained in:
@@ -247,6 +247,9 @@ public class NetDiskService extends BaseService<NetDiskEntity, NetDiskRepository
|
||||
entity.setOrganizationId(Ctx.currentUser().getOrganizationId());
|
||||
entity.setParent(parent);
|
||||
save(entity);
|
||||
if (parent.getChildren() == null){
|
||||
parent.setChildren(new ArrayList<>());
|
||||
}
|
||||
parent.getChildren().add(entity);
|
||||
|
||||
batchCreateDir0(entity, path.subList(1, path.size()));
|
||||
@@ -373,6 +376,8 @@ public class NetDiskService extends BaseService<NetDiskEntity, NetDiskRepository
|
||||
@SneakyThrows
|
||||
public NetDiskDto createFile(CreateFileDto request) {
|
||||
|
||||
resolveNameWithPath(request);
|
||||
|
||||
validateFileName(request.getName());
|
||||
request.setName(createNewFileName(request.getParent(), request.getName()));
|
||||
|
||||
@@ -414,6 +419,40 @@ public class NetDiskService extends BaseService<NetDiskEntity, NetDiskRepository
|
||||
return this.mapper.toDto(entity);
|
||||
}
|
||||
|
||||
private void resolveNameWithPath(CreateFileDto request) {
|
||||
|
||||
|
||||
if (request.getName().contains("/")){
|
||||
String oldId = request.getParent();
|
||||
String[] split = request.getName().split("/");
|
||||
request.setName(split[split.length - 1]);
|
||||
|
||||
NetDiskEntity current = get(request.getParent());
|
||||
|
||||
for(int i = 0; i < split.length - 1; i++) {
|
||||
|
||||
|
||||
String name = split[i];
|
||||
|
||||
if (StringUtils.isEmpty(name)){
|
||||
continue;
|
||||
}
|
||||
|
||||
if (current.getChildren() == null || current.getChildren().stream().noneMatch(x -> x.getName().equals(name))){
|
||||
|
||||
throw new BizException("路径不存在: " + request.getName());
|
||||
}else {
|
||||
current = current.getChildren().stream().filter(x -> x.getName().equals(name)).findFirst().get();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
request.setParent(current.getId());
|
||||
|
||||
log.info("解析路径 {} 为 id {}, oldId {}", request.getName(), request.getParent(), oldId);
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public NetDiskDto createFileSlice(CreateFileDto request) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user