diff --git a/src/main/java/run/halo/app/controller/content/MainController.java b/src/main/java/run/halo/app/controller/content/MainController.java index 12b95ffd2..d3fb601a0 100644 --- a/src/main/java/run/halo/app/controller/content/MainController.java +++ b/src/main/java/run/halo/app/controller/content/MainController.java @@ -1,9 +1,18 @@ package run.halo.app.controller.content; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseBody; +import run.halo.app.exception.ServiceException; +import run.halo.app.model.entity.User; +import run.halo.app.model.properties.BlogProperties; import run.halo.app.model.support.HaloConst; +import run.halo.app.service.OptionService; +import run.halo.app.service.UserService; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; /** * Admin page. @@ -14,6 +23,14 @@ import run.halo.app.model.support.HaloConst; @Controller public class MainController { + private final UserService userService; + + private final OptionService optionService; + + public MainController(UserService userService, OptionService optionService) { + this.userService = userService; + this.optionService = optionService; + } @GetMapping("/admin") public String admin() { @@ -30,4 +47,20 @@ public class MainController { public String version() { return HaloConst.HALO_VERSION; } + + @GetMapping("/user/avatar") + public void avatar(HttpServletResponse response) throws IOException { + User user = userService.getCurrentUser().orElseThrow(() -> new ServiceException("Can not find blog owner")); + if (StringUtils.isNotEmpty(user.getAvatar())) { + response.sendRedirect(user.getAvatar()); + } + } + + @GetMapping("/blog/logo") + public void logo(HttpServletResponse response) throws IOException { + String blogLogo = optionService.getByProperty(BlogProperties.BLOG_LOGO).orElse("").toString(); + if(StringUtils.isNotEmpty(blogLogo)){ + response.sendRedirect(blogLogo); + } + } }