refactor(系统设置): 首页图片代码优化

This commit is contained in:
WangXu10 2023-08-11 17:21:20 +08:00 committed by 刘瑞斌
parent eaba620fde
commit 914397be18
1 changed files with 12 additions and 15 deletions

View File

@ -29,6 +29,7 @@ public class BaseDisplayService {
public ResponseEntity<byte[]> getFile(String fileName) throws IOException { public ResponseEntity<byte[]> getFile(String fileName) throws IOException {
MediaType contentType = MediaType.parseMediaType("application/octet-stream");
byte[] bytes = null; byte[] bytes = null;
SystemParameter systemParameter = systemParameterMapper.selectByPrimaryKey("ui." + fileName); SystemParameter systemParameter = systemParameterMapper.selectByPrimaryKey("ui." + fileName);
if (systemParameter != null) { if (systemParameter != null) {
@ -41,32 +42,28 @@ public class BaseDisplayService {
} catch (Exception e) { } catch (Exception e) {
throw new MSException("get file error"); 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) { if (bytes == null) {
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(getClass().getClassLoader()); PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(getClass().getClassLoader());
switch (fileName) { switch (fileName) {
case "icon": case "icon" ->
bytes = IOUtils.toByteArray(resolver.getResource("/static/favicon.ico").getInputStream()); bytes = IOUtils.toByteArray(resolver.getResource("/static/favicon.ico").getInputStream());
break; case "logoPlatform" -> {
case "logoPlatform":
bytes = IOUtils.toByteArray(resolver.getResource("/static/images/MS-full-logo.svg").getInputStream()); bytes = IOUtils.toByteArray(resolver.getResource("/static/images/MS-full-logo.svg").getInputStream());
contentType = MediaType.valueOf("image/svg+xml"); contentType = MediaType.valueOf("image/svg+xml");
break; }
case "loginImage": case "loginImage" ->
bytes = IOUtils.toByteArray(resolver.getResource("/static/images/login-banner.jpg").getInputStream()); bytes = IOUtils.toByteArray(resolver.getResource("/static/images/login-banner.jpg").getInputStream());
break; default -> {
default:
bytes = IOUtils.toByteArray(resolver.getResource("/static/images/login-logo.svg").getInputStream()); bytes = IOUtils.toByteArray(resolver.getResource("/static/images/login-logo.svg").getInputStream());
contentType = MediaType.valueOf("image/svg+xml"); 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() return ResponseEntity.ok()
.contentType(contentType) .contentType(contentType)