mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 15:55:18 +08:00
完善网盘
This commit is contained in:
@@ -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) {
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user