From 6f1104c040c63d21b1e998b5ba3690205cf8f71b Mon Sep 17 00:00:00 2001 From: XaoLi717 <144221124+XaoLi717@users.noreply.github.com> Date: Tue, 22 Oct 2024 16:14:09 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infra/framework/file/core/client/ftp/FtpFileClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/file/core/client/ftp/FtpFileClient.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/file/core/client/ftp/FtpFileClient.java index 062d838..1c71bd9 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/file/core/client/ftp/FtpFileClient.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/file/core/client/ftp/FtpFileClient.java @@ -74,4 +74,4 @@ public class FtpFileClient extends AbstractFileClient { return config.getBasePath() + path; } -} \ No newline at end of file +} From 13967f2a1ba80f6d15d7217f232bf0d3c5ff4ae0 Mon Sep 17 00:00:00 2001 From: XaoLi717 <144221124+XaoLi717@users.noreply.github.com> Date: Wed, 23 Oct 2024 10:23:36 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=8C=89=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admin/file/FileController.java | 12 +++++++++--- .../file/core/client/local/LocalFileClient.java | 16 ++++++++++++---- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java index db137d5..b3bbac0 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java @@ -66,23 +66,29 @@ public class FileController { return success(true); } - @GetMapping("/{configId}/get/**") + @GetMapping("/{configId}/get/{fileDate}/**") @PermitAll @Operation(summary = "下载文件") @Parameter(name = "configId", description = "配置编号", required = true) public void getFileContent(HttpServletRequest request, HttpServletResponse response, + @PathVariable("fileDate") String fileDate, @PathVariable("configId") Long configId) throws Exception { // 获取请求的路径 String path = StrUtil.subAfter(request.getRequestURI(), "/get/", false); if (StrUtil.isEmpty(path)) { throw new IllegalArgumentException("结尾的 path 路径必须传递"); } - // 解码,解决中文路径的问题 https://gitee.com/zhijiantianya/ruoyi-vue-pro/pulls/807/ path = URLUtil.decode(path); + //去除路径时间信息 + String[] parts = path.split("/"); + if (parts.length > 1) { path = parts[1]; } + + //拼接时间路径 + String filePath = fileDate+"\\"+path; // 读取内容 - byte[] content = fileService.getFileContent(configId, path); + byte[] content = fileService.getFileContent(configId, filePath); if (content == null) { log.warn("[getFileContent][configId({}) path({}) 文件不存在]", configId, path); response.setStatus(HttpStatus.NOT_FOUND.value()); diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/file/core/client/local/LocalFileClient.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/file/core/client/local/LocalFileClient.java index a919690..63b71bf 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/file/core/client/local/LocalFileClient.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/file/core/client/local/LocalFileClient.java @@ -4,6 +4,8 @@ import cn.hutool.core.io.FileUtil; import cn.iocoder.yudao.module.infra.framework.file.core.client.AbstractFileClient; import java.io.File; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; /** * 本地文件客户端 @@ -26,11 +28,17 @@ public class LocalFileClient extends AbstractFileClient { @Override public String upload(byte[] content, String path, String type) { - // 执行写入 - String filePath = getFilePath(path); + //文件路径加上当前时间 + LocalDateTime now = LocalDateTime.now(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + String date = now.format(formatter); //当前时间 + String fPath = date+"\\"+path; //文件路径 + String uPath = date+"/"+path; //url路径 + // 执行写入文件路径 + String filePath = getFilePath(fPath); FileUtil.writeBytes(content, filePath); - // 拼接返回路径 - return super.formatFileUrl(config.getDomain(), path); + // 拼接url路径返回路径 + return super.formatFileUrl(config.getDomain(), uPath); } @Override From 9ece7c8f1cfcc81382f381ebbf64ed34a7bdaf95 Mon Sep 17 00:00:00 2001 From: XaoLi717 <144221124+XaoLi717@users.noreply.github.com> Date: Wed, 23 Oct 2024 10:24:46 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=8C=89=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao/module/infra/controller/admin/file/FileController.java | 1 + 1 file changed, 1 insertion(+) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java index b3bbac0..07d44d2 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java @@ -79,6 +79,7 @@ public class FileController { if (StrUtil.isEmpty(path)) { throw new IllegalArgumentException("结尾的 path 路径必须传递"); } + // 解码,解决中文路径的问题 https://gitee.com/zhijiantianya/ruoyi-vue-pro/pulls/807/ path = URLUtil.decode(path); //去除路径时间信息