From abfd9cff5276fd8bc3f9e37425b2d24b1dd3637e Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Fri, 17 Nov 2023 17:34:31 +0800 Subject: [PATCH] =?UTF-8?q?style(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=87=E4=BB=B6=E7=AE=A1=E7=90=86svg?= =?UTF-8?q?=E5=9B=BE=E6=A0=87=E7=9A=84=E9=A2=84=E8=A7=88=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/service/FileMetadataService.java | 4 +++- .../FileManagementControllerTests.java | 12 ++++++++++++ .../resources/file/icon_file-unknow_colorful.svg | 10 ++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 backend/services/project-management/src/test/resources/file/icon_file-unknow_colorful.svg diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java index 5b91fd8b54..5c02faa3d4 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java @@ -480,7 +480,9 @@ public class FileMetadataService { public ResponseEntity downloadPreviewImgById(String id) throws Exception { FileMetadata fileMetadata = fileMetadataMapper.selectByPrimaryKey(id); String previewImgPath = null; - if (TempFileUtils.isImage(fileMetadata.getType())) { + if (StringUtils.equalsIgnoreCase(fileMetadata.getType(), "svg")) { + return this.downloadById(id); + } else if (TempFileUtils.isImage(fileMetadata.getType())) { if (TempFileUtils.isImgPreviewFileExists(fileMetadata.getId())) { previewImgPath = TempFileUtils.getPreviewImgFilePath(fileMetadata.getId()); } else { diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileManagementControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileManagementControllerTests.java index 5bd5152748..094206b434 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileManagementControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileManagementControllerTests.java @@ -440,6 +440,17 @@ public class FileManagementControllerTests extends BaseTest { fileUploadRequest.setEnable(false); //小型图片文件,用于测试预览图下载 + filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/icon_file-unknow_colorful.svg")).getPath(); + file = new MockMultipartFile("file", "icon_file-unknow_colorful.svg", MediaType.APPLICATION_OCTET_STREAM_VALUE, FileManagementBaseUtils.getFileBytes(filePath)); + paramMap = new LinkedMultiValueMap<>(); + paramMap.add("file", file); + paramMap.add("request", JSON.toJSONString(fileUploadRequest)); + mvcResult = this.requestMultipartWithOkAndReturn(FileManagementRequestUtils.URL_FILE_UPLOAD, paramMap); + returnId = JSON.parseObject(mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData().toString(); + checkLog(returnId, OperationLogType.ADD, FileManagementRequestUtils.URL_FILE_UPLOAD); + FILE_ID_PATH.put(returnId, filePath); + + //svg文件,用于测试预览图下载 filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/1182937072541700.jpg")).getPath(); file = new MockMultipartFile("file", "1182937072541700.jpg", MediaType.APPLICATION_OCTET_STREAM_VALUE, FileManagementBaseUtils.getFileBytes(filePath)); paramMap = new LinkedMultiValueMap<>(); @@ -449,6 +460,7 @@ public class FileManagementControllerTests extends BaseTest { returnId = JSON.parseObject(mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData().toString(); checkLog(returnId, OperationLogType.ADD, FileManagementRequestUtils.URL_FILE_UPLOAD); FILE_ID_PATH.put(returnId, filePath); + uploadedFileTypes.add("svg"); //检查文件类型获取接口有没有获取到数据 fileTypes = this.getFileType(); diff --git a/backend/services/project-management/src/test/resources/file/icon_file-unknow_colorful.svg b/backend/services/project-management/src/test/resources/file/icon_file-unknow_colorful.svg new file mode 100644 index 0000000000..fcb6ac391b --- /dev/null +++ b/backend/services/project-management/src/test/resources/file/icon_file-unknow_colorful.svg @@ -0,0 +1,10 @@ + + + + + + + + + +