From ac3b4283a32a8a985fe9aaaae87be5bbf85951f1 Mon Sep 17 00:00:00 2001 From: zhaojun <873019219@qq.com> Date: Sat, 27 May 2023 16:50:14 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=96=B0=E5=A2=9E=E7=BD=91?= =?UTF-8?q?=E7=AB=99=20favicon=20=E7=BD=91=E7=AB=99=E5=9C=B0=E5=9D=80?= =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E5=8A=9F=E8=83=BD=EF=BC=8C=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E7=9A=84=20html=20=E6=98=AF=E5=B7=B2=E7=BB=8F?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BF=87=E7=9A=84=EF=BC=8C=E4=B8=8D=E6=98=AF?= =?UTF-8?q?=E7=AD=89=E5=BE=85=E9=A1=B5=E9=9D=A2=E5=8A=A0=E8=BD=BD=E5=AE=8C?= =?UTF-8?q?=E5=86=8D=E4=BF=AE=E6=94=B9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/controller/FrontIndexController.java | 40 +++++++++++++++++-- .../request/UpdateSiteSettingRequest.java | 4 ++ ...tem_config_add_field_favicon_url_field.sql | 1 + ...tem_config_add_field_favicon_url_field.sql | 1 + 4 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 src/main/resources/db/migration-mysql/V20__system_config_add_field_favicon_url_field.sql create mode 100644 src/main/resources/db/migration-sqlite/V20__system_config_add_field_favicon_url_field.sql diff --git a/src/main/java/im/zhaojun/zfile/core/controller/FrontIndexController.java b/src/main/java/im/zhaojun/zfile/core/controller/FrontIndexController.java index 496550a..ae88c7f 100644 --- a/src/main/java/im/zhaojun/zfile/core/controller/FrontIndexController.java +++ b/src/main/java/im/zhaojun/zfile/core/controller/FrontIndexController.java @@ -1,7 +1,18 @@ package im.zhaojun.zfile.core.controller; +import cn.hutool.core.util.StrUtil; +import im.zhaojun.zfile.module.config.model.dto.SystemConfigDTO; +import im.zhaojun.zfile.module.config.service.SystemConfigService; +import org.apache.commons.io.IOUtils; +import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.annotation.Resource; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; /** * 处理前端首页 Controller @@ -11,15 +22,36 @@ import org.springframework.web.bind.annotation.RequestMapping; @Controller public class FrontIndexController { + @Resource + private SystemConfigService systemConfigService; + + /** * 所有未找到的页面都跳转到首页, 用户解决 vue history 直接访问 404 的问题 + * 同时, 读取 index.html 文件, 修改 title 和 favicon 后返回. * * @return 转发到 /index.html */ - @RequestMapping(value = "/**/{[path:[^\\.]*}") - public String redirect() { - // Forward to home page so that route is preserved. - return "forward:/"; + @RequestMapping(value = {"/**/{[path:[^\\.]*}", "/"}) + @ResponseBody + public String redirect() throws IOException { + // 读取 resources/static/index.html 文件修改 title 和 favicon 后返回 + ClassPathResource resource = new ClassPathResource("static/index.html"); + InputStream inputStream = resource.getInputStream(); + String content = IOUtils.toString(inputStream, StandardCharsets.UTF_8); + + SystemConfigDTO systemConfig = systemConfigService.getSystemConfig(); + String siteName = systemConfig.getSiteName(); + if (StrUtil.isNotBlank(siteName)) { + content = content.replace("