|
|
@@ -1,145 +1,8 @@
|
|
|
package cn.reghao.bnt.web.blog;
|
|
|
|
|
|
-import cn.reghao.bnt.web.sys.service.FileService;
|
|
|
-import cn.reghao.jutil.web.ServletUtil;
|
|
|
-import org.springframework.data.domain.PageRequest;
|
|
|
-import org.springframework.data.domain.Pageable;
|
|
|
-import org.springframework.data.domain.Sort;
|
|
|
-import org.springframework.stereotype.Controller;
|
|
|
-import org.springframework.ui.ModelMap;
|
|
|
-import org.springframework.web.bind.ServletRequestUtils;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
-import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
-
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.io.IOException;
|
|
|
-import java.net.URLDecoder;
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
-
|
|
|
/**
|
|
|
* @author reghao
|
|
|
* @date 2024-07-24 13:50:19
|
|
|
*/
|
|
|
-@Controller
|
|
|
public class BlogController {
|
|
|
- private final FileService fileService;
|
|
|
-
|
|
|
- public BlogController(FileService fileService) {
|
|
|
- this.fileService = fileService;
|
|
|
- }
|
|
|
-
|
|
|
- @GetMapping(value = {"/blog", "/blog/index"})
|
|
|
- public String index(ModelMap model, HttpServletRequest request) {
|
|
|
- // 调用 ContentsDirective
|
|
|
- String order = ServletRequestUtils.getStringParameter(request, "order", "newest");
|
|
|
- int pageNo = ServletRequestUtils.getIntParameter(request, "pageNo", 1);
|
|
|
- //model.put("user", accountQuery.getUserCard());
|
|
|
- model.put("order", order);
|
|
|
- model.put("pageNo", pageNo);
|
|
|
-
|
|
|
- setChannels(model);
|
|
|
- return "/blog/index";
|
|
|
- }
|
|
|
-
|
|
|
- @GetMapping("/category")
|
|
|
- public String category(ModelMap model) {
|
|
|
- /*List<CategoryCount> list = categoryService.findCategoryCountByPage(CategoryType.Category.getValue(), 1, 100).getContent();
|
|
|
- model.put("results", list);
|
|
|
-
|
|
|
- setChannels(model);*/
|
|
|
- return "/blog/index";
|
|
|
- }
|
|
|
-
|
|
|
- @GetMapping("/category/{name}")
|
|
|
- public String category1(@PathVariable("name") String name, ModelMap model) {
|
|
|
- /*int pageNo = ServletRequestUtils.getIntParameter(ServletUtil.getRequest(), "pageNo", 1);
|
|
|
- Page<UserArticle> page = articleQuery.findByPage1(10, pageNo, name, 1);
|
|
|
- model.put("results", page);
|
|
|
- model.put("name", name);
|
|
|
- model.put("user", accountQuery.getUserCard());
|
|
|
-
|
|
|
- setChannels(model);*/
|
|
|
- return "/blog/index";
|
|
|
- }
|
|
|
-
|
|
|
- @GetMapping("/tag")
|
|
|
- public String tag(ModelMap model) {
|
|
|
- /*List<CategoryCount> list = categoryService.findCategoryCountByPage(CategoryType.Tag.getValue(), 1, 100).getContent();
|
|
|
- model.put("results", list);
|
|
|
-
|
|
|
- setChannels(model);*/
|
|
|
- return "/blog/index";
|
|
|
- }
|
|
|
-
|
|
|
- @GetMapping("/tag/{name}")
|
|
|
- public String tag1(@PathVariable String name, ModelMap model) {
|
|
|
- /*int pageNo = ServletRequestUtils.getIntParameter(ServletUtil.getRequest(), "pageNo", 1);
|
|
|
- Page<UserArticle> page = articleQuery.findByPage1(10, pageNo, name, 2);
|
|
|
- model.put("results", page);
|
|
|
- model.put("name", name);
|
|
|
- model.put("user", accountQuery.getUserCard());
|
|
|
-
|
|
|
- setChannels(model);*/
|
|
|
- return "/blog/index";
|
|
|
- }
|
|
|
-
|
|
|
- @GetMapping("/archive")
|
|
|
- public String archive(ModelMap model) {
|
|
|
- /*List<ArchiveArticle> results = articleQuery.getArchiveArticles();
|
|
|
- model.put("user", accountQuery.getUserCard());
|
|
|
- model.put("results", results);
|
|
|
-
|
|
|
- setChannels(model);*/
|
|
|
- return "/blog/index";
|
|
|
- }
|
|
|
-
|
|
|
- @GetMapping("/post/{articleId}")
|
|
|
- public String article(@PathVariable("articleId") String articleId, ModelMap model) {
|
|
|
- /*ArticleVO articleVO = articleQuery.getArticle(articleId);
|
|
|
- if (articleVO == null) {
|
|
|
- model.put("title", "Not Found");
|
|
|
- model.put("content", "文章不存在");
|
|
|
- setChannels(model);
|
|
|
- return "/classic/zzz/notfound";
|
|
|
- }
|
|
|
-
|
|
|
- articleViewService.incr(articleId);
|
|
|
- model.put("user", accountQuery.getUserCard());
|
|
|
- model.put("view", articleVO);
|
|
|
- setChannels(model);*/
|
|
|
- return "/blog/index";
|
|
|
- }
|
|
|
-
|
|
|
- @GetMapping("/search")
|
|
|
- public String search(String kw, ModelMap model) {
|
|
|
- Pageable pageable = PageRequest.of(0, 10, Sort.by(Sort.Direction.ASC, "createTime"));
|
|
|
- /*Page<UserArticle> page = articleSearch.search(kw, pageable);
|
|
|
-
|
|
|
- model.put("results", page);
|
|
|
- model.put("kw", kw);
|
|
|
- model.put("user", accountQuery.getUserCard());
|
|
|
-
|
|
|
- setChannels(model);*/
|
|
|
- return "/blog/index";
|
|
|
- }
|
|
|
-
|
|
|
- @GetMapping("/file/**")
|
|
|
- @ResponseBody
|
|
|
- public void getFile() throws IOException {
|
|
|
- HttpServletRequest servletRequest = ServletUtil.getRequest();
|
|
|
- String uri = servletRequest.getRequestURI();
|
|
|
- String uri1 = URLDecoder.decode(uri, StandardCharsets.UTF_8);
|
|
|
- String objectName = uri1.replaceFirst("/", "");
|
|
|
- fileService.getFile(objectName);
|
|
|
- }
|
|
|
-
|
|
|
- private void setChannels(ModelMap model) {
|
|
|
- /*List<Channel> channels = new ArrayList<>();
|
|
|
- channels.add(new Channel("分类", "category"));
|
|
|
- channels.add(new Channel("标签", "tag"));
|
|
|
- channels.add(new Channel("归档", "archive"));
|
|
|
- model.put("searchBox", true);
|
|
|
- model.put("channels", channels);*/
|
|
|
- }
|
|
|
}
|