From 00c41fbbd333bac2f4dd9e07f7ffb8d3e3ba5187 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Sun, 1 Feb 2026 21:00:07 +0800 Subject: [PATCH] =?UTF-8?q?refactor(knowledge-item):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=9F=A5=E8=AF=86=E9=A1=B9=E9=A2=84=E8=A7=88=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将文件路径验证逻辑从方法开始位置移动到实际使用位置 - 修复了预览文件名获取方式,直接从相对路径解析文件名 - 确保文件存在性检查只在需要时执行 - 提高了代码可读性和执行效率 --- .../application/KnowledgeItemApplicationService.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/services/data-management-service/src/main/java/com/datamate/datamanagement/application/KnowledgeItemApplicationService.java b/backend/services/data-management-service/src/main/java/com/datamate/datamanagement/application/KnowledgeItemApplicationService.java index d98c9d8..7dc7362 100644 --- a/backend/services/data-management-service/src/main/java/com/datamate/datamanagement/application/KnowledgeItemApplicationService.java +++ b/backend/services/data-management-service/src/main/java/com/datamate/datamanagement/application/KnowledgeItemApplicationService.java @@ -366,12 +366,9 @@ public class KnowledgeItemApplicationService { String relativePath = knowledgeItem.getContent(); BusinessAssert.isTrue(StringUtils.isNotBlank(relativePath), CommonErrorCode.PARAM_ERROR); - Path filePath = resolveKnowledgeItemStoragePath(relativePath); - BusinessAssert.isTrue(Files.exists(filePath) && Files.isRegularFile(filePath), CommonErrorCode.PARAM_ERROR); - String previewName = StringUtils.isNotBlank(knowledgeItem.getSourceFileId()) ? knowledgeItem.getSourceFileId() - : filePath.getFileName().toString(); + : Paths.get(relativePath).getFileName().toString(); if (knowledgeItemPreviewService.isOfficeDocument(previewName)) { KnowledgeItemPreviewService.PreviewFile previewFile = knowledgeItemPreviewService.resolveReadyPreviewFile(setId, knowledgeItem); @@ -393,6 +390,9 @@ public class KnowledgeItemApplicationService { return; } + Path filePath = resolveKnowledgeItemStoragePath(relativePath); + BusinessAssert.isTrue(Files.exists(filePath) && Files.isRegularFile(filePath), CommonErrorCode.PARAM_ERROR); + String contentType = null; try { contentType = Files.probeContentType(filePath);