Support blog logo and user avatar url.

pull/165/head
ruibaby 2019-05-18 00:31:30 +08:00
parent d61a4e5c9f
commit c932e4319a
1 changed files with 33 additions and 0 deletions

View File

@ -1,9 +1,18 @@
package run.halo.app.controller.content; package run.halo.app.controller.content;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody; 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.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. * Admin page.
@ -14,6 +23,14 @@ import run.halo.app.model.support.HaloConst;
@Controller @Controller
public class MainController { 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") @GetMapping("/admin")
public String admin() { public String admin() {
@ -30,4 +47,20 @@ public class MainController {
public String version() { public String version() {
return HaloConst.HALO_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);
}
}
} }