完善网盘

This commit is contained in:
2024-01-13 19:59:55 +08:00
parent 64cea704b2
commit 3269609091
2 changed files with 31 additions and 32 deletions

View File

@@ -305,7 +305,7 @@ public class NetDiskController {
* @param response
*/
@GetMapping("/downloadBatch")
@SysLog(action = "downloadBatch", message = "ids")
@SysLog(action = "downloadBatch")
@SignCheck(false)
public void downloadDir(@RequestParam("ids") String ids, HttpServletResponse response) {

View File

@@ -247,7 +247,7 @@ public class NetDiskService extends BaseService<NetDiskEntity, NetDiskRepository
entity.setOrganizationId(Ctx.currentUser().getOrganizationId());
entity.setParent(parent);
save(entity);
if (parent.getChildren() == null){
if (parent.getChildren() == null) {
parent.setChildren(new ArrayList<>());
}
parent.getChildren().add(entity);
@@ -421,30 +421,33 @@ public class NetDiskService extends BaseService<NetDiskEntity, NetDiskRepository
private void resolveNameWithPath(CreateFileDto request) {
if (request.getName().contains("/")){
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++) {
for (int i = 0; i < split.length - 1; i++) {
String name = split[i];
if (StringUtils.isEmpty(name)){
if (StringUtils.isEmpty(name)) {
continue;
}
if (current.getChildren() == null || current.getChildren().stream().noneMatch(x -> x.getName().equals(name))){
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();
} else {
current =
current.getChildren().stream()
.filter(x -> x.getName().equals(name))
.findFirst()
.get();
}
}
request.setParent(current.getId());
@@ -816,10 +819,10 @@ public class NetDiskService extends BaseService<NetDiskEntity, NetDiskRepository
response.setContentType("application/zip");
// 设置响应头指定ZIP文件名
String zipName = URLEncoder.encode("批量下载" + LocalDate.now() + ".zip", StandardCharsets.UTF_8);
String zipName =
URLEncoder.encode("批量下载" + LocalDate.now() + ".zip", StandardCharsets.UTF_8);
response.setHeader("Content-Disposition", "attachment; filename=" + zipName);
StopWatch stopWatch = new StopWatch("批量下载 "+ StringUtils.join(request.getIds(), ","));
StopWatch stopWatch = new StopWatch("批量下载 " + StringUtils.join(request.getIds(), ","));
@Cleanup("close")
ZipArchiveOutputStream zipArchiveOutputStream =
@@ -829,16 +832,6 @@ public class NetDiskService extends BaseService<NetDiskEntity, NetDiskRepository
NetDiskEntity entity = get(id);
stopWatch.start(
"下载文件夹/文件夹 "
+ entity.getName()
+ " "
+ entity.getEntryTypeName()
+ " "
+ entity.getId());
zipEntity(entity, zipArchiveOutputStream, entity, stopWatch);
log.info(stopWatch.prettyPrint());
@@ -858,6 +851,7 @@ public class NetDiskService extends BaseService<NetDiskEntity, NetDiskRepository
parts.addFirst(entry.getName());
entry = entry.getParent();
}
parts.addFirst(root.getName());
return StringUtils.join(parts, "/") + (isDir ? "/" : "");
}
@@ -1004,17 +998,27 @@ public class NetDiskService extends BaseService<NetDiskEntity, NetDiskRepository
NetDiskEntity root,
StopWatch stopWatch) {
String fullName = getFullName(root, dir);
if (dir.getEntryType().equals("0")) {
stopWatch.start("创建目录 " + dir.getName() + " " + dir.getId());
zipArchiveOutputStream.putArchiveEntry(new ZipArchiveEntry(getFullName(root, dir)));
stopWatch.start("创建目录 " + dir.getName() + " " + fullName + " " + dir.getId());
zipArchiveOutputStream.putArchiveEntry(new ZipArchiveEntry(fullName));
zipArchiveOutputStream.closeArchiveEntry();
stopWatch.stop();
if (dir.getChildren() != null) {
for (NetDiskEntity child : dir.getChildren()) {
zipEntity(child, zipArchiveOutputStream, root, stopWatch);
}
}
} else {
zipArchiveOutputStream.putArchiveEntry(new ZipArchiveEntry(getFullName(root, dir)));
zipArchiveOutputStream.putArchiveEntry(new ZipArchiveEntry(fullName));
stopWatch.start("下载文件 " + dir.getName() + " " + dir.getId());
OSSObject ossObject =
@@ -1024,11 +1028,6 @@ public class NetDiskService extends BaseService<NetDiskEntity, NetDiskRepository
stopWatch.stop();
zipArchiveOutputStream.closeArchiveEntry();
for (NetDiskEntity child : dir.getChildren()) {
zipEntity(child, zipArchiveOutputStream, root, stopWatch);
}
}
}