diff --git a/src/main/java/com/alist/api/common/modules/file/dto/FileMoveTaskDto.java b/src/main/java/com/alist/api/common/modules/file/dto/FileMoveTaskDto.java index 6307e60..9845a31 100644 --- a/src/main/java/com/alist/api/common/modules/file/dto/FileMoveTaskDto.java +++ b/src/main/java/com/alist/api/common/modules/file/dto/FileMoveTaskDto.java @@ -15,6 +15,8 @@ public class FileMoveTaskDto { private Long sizeBytes; private Long uploadedBytes; + private String folderPath; + private String saveName; private String savePath; private String ext; diff --git a/src/main/java/com/alist/api/common/modules/file/service/FileService.java b/src/main/java/com/alist/api/common/modules/file/service/FileService.java index 7360a53..7c693ac 100644 --- a/src/main/java/com/alist/api/common/modules/file/service/FileService.java +++ b/src/main/java/com/alist/api/common/modules/file/service/FileService.java @@ -382,13 +382,36 @@ public class FileService { + (ext.isBlank() ? "" : "." + ext); LocalDate now = LocalDate.now(); + String folder = normalizeFolderPath(task.getFolderPath()); + return Paths.get(uploadFinalRoot, + folder, String.valueOf(now.getYear()), String.format("%02d", now.getMonthValue()), String.format("%02d", now.getDayOfMonth()), fileName); } + private String normalizeFolderPath(String folderPath) { + if (folderPath == null || folderPath.isBlank() || "/".equals(folderPath.trim())) { + return "default"; + } + + String s = folderPath.trim().replace("\\", "/"); + + // 앞뒤 슬래시 제거 + while (s.startsWith("/")) s = s.substring(1); + while (s.endsWith("/")) s = s.substring(0, s.length() - 1); + + // 경로 역참조 차단 + s = s.replace("..", ""); + + // 비어버리면 기본 폴더 + if (s.isBlank()) return "default"; + + return s; + } + private String toSavePath(Path finalPath) { // DB 저장용 상대경로(운영 규칙에 맞게 조정) // 예: /2026/03/09/xxx.zip diff --git a/src/main/resources/mapper/common/file/FileMapper.xml b/src/main/resources/mapper/common/file/FileMapper.xml index 77cd76c..8fbe4f7 100644 --- a/src/main/resources/mapper/common/file/FileMapper.xml +++ b/src/main/resources/mapper/common/file/FileMapper.xml @@ -195,12 +195,27 @@