From 2d1bc74099b386dbf190c718c059a23e3dca2100 Mon Sep 17 00:00:00 2001 From: sdw086 Date: Mon, 9 Mar 2026 17:29:27 +0900 Subject: [PATCH] =?UTF-8?q?[=ED=8C=8C=EC=9D=BC=20=EC=97=85=EB=A1=9C?= =?UTF-8?q?=EB=93=9C]=20tusHook=20=EC=9E=91=EC=97=85=20-=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=9D=B4=EB=8F=99=EC=9E=91=EC=97=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/file/dto/FileMoveTaskDto.java | 2 ++ .../modules/file/service/FileService.java | 23 ++++++++++++++++ .../mapper/common/file/FileMapper.xml | 27 ++++++++++++++----- 3 files changed, 46 insertions(+), 6 deletions(-) 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 @@