From 914397be18e5726126f3fa711ab3507101138e85 Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Fri, 11 Aug 2023 17:21:20 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):?= =?UTF-8?q?=20=E9=A6=96=E9=A1=B5=E5=9B=BE=E7=89=87=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/service/BaseDisplayService.java | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseDisplayService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseDisplayService.java index 48521855f6..5c0a90d060 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseDisplayService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/BaseDisplayService.java @@ -29,6 +29,7 @@ public class BaseDisplayService { public ResponseEntity getFile(String fileName) throws IOException { + MediaType contentType = MediaType.parseMediaType("application/octet-stream"); byte[] bytes = null; SystemParameter systemParameter = systemParameterMapper.selectByPrimaryKey("ui." + fileName); if (systemParameter != null) { @@ -41,32 +42,28 @@ public class BaseDisplayService { } catch (Exception e) { throw new MSException("get file error"); } + if (systemParameter.getParamValue().endsWith(".svg")) { + contentType = MediaType.valueOf("image/svg+xml"); + } } - MediaType contentType = MediaType.parseMediaType("application/octet-stream"); if (bytes == null) { PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(getClass().getClassLoader()); switch (fileName) { - case "icon": - bytes = IOUtils.toByteArray(resolver.getResource("/static/favicon.ico").getInputStream()); - break; - case "logoPlatform": + case "icon" -> + bytes = IOUtils.toByteArray(resolver.getResource("/static/favicon.ico").getInputStream()); + case "logoPlatform" -> { bytes = IOUtils.toByteArray(resolver.getResource("/static/images/MS-full-logo.svg").getInputStream()); contentType = MediaType.valueOf("image/svg+xml"); - break; - case "loginImage": - bytes = IOUtils.toByteArray(resolver.getResource("/static/images/login-banner.jpg").getInputStream()); - break; - default: + } + case "loginImage" -> + bytes = IOUtils.toByteArray(resolver.getResource("/static/images/login-banner.jpg").getInputStream()); + default -> { bytes = IOUtils.toByteArray(resolver.getResource("/static/images/login-logo.svg").getInputStream()); contentType = MediaType.valueOf("image/svg+xml"); - break; + } } } - String[] split = systemParameter.getParamValue().split("[.\n]"); - if (StringUtils.equalsAnyIgnoreCase("svg", split[split.length - 1])) { - contentType = MediaType.valueOf("image/svg+xml"); - } return ResponseEntity.ok() .contentType(contentType)