Skip to content

Commit

Permalink
Merge pull request #172 from halo-dev/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ruibaby authored May 31, 2019
2 parents b50ed6b + 1bf30b0 commit d6bfa07
Show file tree
Hide file tree
Showing 106 changed files with 934 additions and 7,968 deletions.
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

**我确定我已经查看了** (标注`[ ]``[x]`)

- [ ] [Halo 使用文档](https://docs.halo.run/)
- [ ] [Halo 使用文档](https://halo.run/docs)
- [ ] [Halo 论坛](https://bbs.halo.run)
- [ ] [Github Wiki 常见问题](https://github.com/halo-dev/halo/wiki/4.-%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98)
- [ ] [其他 Issues](https://github.com/halo-dev/halo/issues)

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@

## 周边

- 后台管理源码:<[https://github.com/halo-dev/halo-admin](https://github.com/halo-dev/halo-admin)>
- 后台管理(halo-admin):<[https://github.com/halo-dev/halo-admin](https://github.com/halo-dev/halo-admin)>
- 独立评论模块(halo-comment):<[https://github.com/halo-dev/halo-comment](https://github.com/halo-dev/halo-comment)>
- 管理 APP(halo-app):<[https://github.com/halo-dev/halo-app](https://github.com/halo-dev/halo-app)>
- 主题仓库:<[https://halo.run/theme](https://halo.run/theme)>
- 管理 APP:<[https://github.com/halo-dev/halo-app](https://github.com/halo-dev/halo-app)>

## 许可证

Expand Down
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ apply plugin: 'io.spring.dependency-management'

group = 'run.halo.app'
archivesBaseName = 'halo'
version = '1.0.0-beta.7'
version = '1.0.0-beta.8'
sourceCompatibility = '1.8'
description = 'Halo, personal blog system developed in Java.'

Expand Down Expand Up @@ -56,6 +56,10 @@ dependencies {
implementation 'com.atlassian.commonmark:commonmark:0.12.1'
implementation 'com.atlassian.commonmark:commonmark-ext-gfm-tables:0.12.1'
implementation 'com.atlassian.commonmark:commonmark-ext-yaml-front-matter:0.12.1'
implementation 'com.atlassian.commonmark:commonmark-ext-autolink:0.12.1'
implementation 'com.atlassian.commonmark:commonmark-ext-gfm-strikethrough:0.12.1'
implementation 'com.atlassian.commonmark:commonmark-ext-heading-anchor:0.12.1'
implementation 'com.atlassian.commonmark:commonmark-ext-ins:0.12.1'
implementation 'io.springfox:springfox-swagger2:2.9.2'
implementation 'io.springfox:springfox-swagger-ui:2.9.2'
implementation 'org.apache.commons:commons-lang3:3.8.1'
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/run/halo/app/config/HaloConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ public FilterRegistrationBean<ApiAuthenticationFilter> apiAuthenticationFilter(H
ApiAuthenticationFilter apiFilter = new ApiAuthenticationFilter(haloProperties, optionService);
apiFilter.addExcludeUrlPatterns(
"/api/content/*/comments",
"/api/content/**/comments/**"
"/api/content/**/comments/**",
"/api/content/options/comment"
);

DefaultAuthenticationFailureHandler failureHandler = new DefaultAuthenticationFailureHandler();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
package run.halo.app.controller.admin.api;

import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import run.halo.app.model.dto.post.BasePostDetailDTO;
import run.halo.app.service.BackupService;

import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

/**
* Backup controller
*
Expand All @@ -19,4 +28,15 @@ public class BackupController {
public BackupController(BackupService backupService) {
this.backupService = backupService;
}

@PostMapping("import/markdowns")
@ApiOperation("Import markdowns")
public List<BasePostDetailDTO> backupMarkdowns(@RequestPart("files") MultipartFile[] files) throws IOException {
List<BasePostDetailDTO> result = new LinkedList<>();
for (MultipartFile file : files) {
BasePostDetailDTO post = backupService.importMarkdowns(file);
result.add(post);
}
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public JournalController(JournalService journalService,
}

@GetMapping
@ApiOperation("Gets latest journals")
@ApiOperation("Lists journals")
public Page<JournalWithCmtCountDTO> pageBy(@PageableDefault(sort = "updateTime", direction = DESC) Pageable pageable,
JournalQuery journalQuery) {
Page<Journal> journalPage = journalService.pageBy(journalQuery, pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void migrateFromVersion_0_4_3(
@ApiParam("This file content type should be json")
@RequestPart("file") MultipartFile file) {
if (optionService.getByPropertyOrDefault(PrimaryProperties.IS_INSTALLED, Boolean.class, false)) {
throw new BadRequestException("You cannot migrate after blog installing");
throw new BadRequestException("不能在博客初始化完成之后迁移数据");
}

recoveryService.migrateFromV0_4_3(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;
import run.halo.app.model.dto.InternalSheetDTO;
import run.halo.app.model.dto.post.BasePostDetailDTO;
import run.halo.app.model.entity.Sheet;
import run.halo.app.model.enums.PostStatus;
Expand All @@ -13,13 +14,15 @@
import run.halo.app.service.SheetService;

import javax.validation.Valid;
import java.util.List;

import static org.springframework.data.domain.Sort.Direction.DESC;

/**
* Sheet controller.
*
* @author johnniang
* @author ryanwang
* @date 19-4-24
*/
@RestController
Expand All @@ -46,6 +49,12 @@ public Page<SheetListVO> pageBy(@PageableDefault(sort = "editTime", direction =
return sheetService.convertToListVo(sheetPage);
}

@GetMapping("internal")
@ApiOperation("Lists internal sheets")
public List<InternalSheetDTO> internalSheets() {
return sheetService.listInternal();
}

@PostMapping
@ApiOperation("Creates a sheet")
public BasePostDetailDTO createBy(@RequestBody @Valid SheetParam sheetParam,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ public void saveSettingsBy(@PathVariable("themeId") String themeId,
themeSettingService.save(settings, themeId);
}

@PutMapping("{themeId}")
public ThemeProperty updateTheme(@PathVariable("themeId") String themeId,
@RequestPart(name = "file", required = false) MultipartFile file) {

return themeService.update(themeId);
}

@DeleteMapping("{themeId}")
@ApiOperation("Deletes a theme")
public void deleteBy(@PathVariable("themeId") String themeId) {
Expand Down Expand Up @@ -145,4 +152,5 @@ public void reload() {
public BaseResponse exists(@RequestParam(value = "template") String template) {
return BaseResponse.ok(themeService.templateExists(template));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import run.halo.app.model.entity.User;
import run.halo.app.model.params.PasswordParam;
import run.halo.app.model.params.UserParam;
import run.halo.app.model.support.BaseResponse;
import run.halo.app.model.support.UpdateCheck;
import run.halo.app.service.UserService;
import run.halo.app.utils.ValidationUtils;
Expand Down Expand Up @@ -45,7 +46,8 @@ public UserDTO updateProfile(@RequestBody UserParam userParam, User user) {
}

@PutMapping("profiles/password")
public void updatePassword(@RequestBody @Valid PasswordParam passwordParam, User user) {
public BaseResponse updatePassword(@RequestBody @Valid PasswordParam passwordParam, User user) {
userService.updatePassword(passwordParam.getOldPassword(), passwordParam.getNewPassword(), user.getId());
return BaseResponse.ok("密码修改成功");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
import org.springframework.web.bind.annotation.*;
import run.halo.app.cache.lock.CacheLock;
import run.halo.app.model.dto.BaseCommentDTO;
import run.halo.app.model.entity.JournalComment;
import run.halo.app.model.enums.CommentStatus;
import run.halo.app.model.params.JournalCommentParam;
import run.halo.app.model.vo.BaseCommentVO;
import run.halo.app.model.vo.BaseCommentWithParentVO;
import run.halo.app.model.vo.CommentWithHasChildrenVO;
import run.halo.app.service.JournalCommentService;
import run.halo.app.service.JournalService;
import run.halo.app.service.OptionService;

import java.util.List;

import static org.springframework.data.domain.Sort.Direction.DESC;

/**
Expand All @@ -39,20 +44,41 @@ public JournalController(JournalService journalService,
this.optionService = optionService;
}

@GetMapping("{journalId:\\d+}/comments/top_view")
public Page<CommentWithHasChildrenVO> listTopComments(@PathVariable("journalId") Integer journalId,
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
Page<CommentWithHasChildrenVO> result = journalCommentService.pageTopCommentsBy(journalId, CommentStatus.PUBLISHED, PageRequest.of(page, optionService.getCommentPageSize(), sort));
return journalCommentService.filterIpAddress(result);
}

@GetMapping("{journalId:\\d+}/comments/{commentParentId:\\d+}/children")
public List<BaseCommentDTO> listChildrenBy(@PathVariable("journalId") Integer journalId,
@PathVariable("commentParentId") Long commentParentId,
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
// Find all children comments
List<JournalComment> postComments = journalCommentService.listChildrenBy(journalId, commentParentId, CommentStatus.PUBLISHED, sort);
// Convert to base comment dto
List<BaseCommentDTO> result = journalCommentService.convertTo(postComments);
return journalCommentService.filterIpAddress(result);
}

@GetMapping("{journalId:\\d+}/comments/tree_view")
@ApiOperation("Lists comments with tree view")
public Page<BaseCommentVO> listCommentsTree(@PathVariable("journalId") Integer journalId,
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
return journalCommentService.pageVosBy(journalId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
Page<BaseCommentVO> result = journalCommentService.pageVosBy(journalId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
return journalCommentService.filterIpAddress(result);
}

@GetMapping("{journalId:\\d+}/comments/list_view")
@ApiOperation("Lists comment with list view")
public Page<BaseCommentWithParentVO> listComments(@PathVariable("journalId") Integer journalId,
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
return journalCommentService.pageWithParentVoBy(journalId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
Page<BaseCommentWithParentVO> result = journalCommentService.pageWithParentVoBy(journalId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
return journalCommentService.filterIpAddress(result);
}

@PostMapping("comments")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import run.halo.app.model.support.BaseResponse;
import run.halo.app.service.OptionService;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -48,4 +49,14 @@ public Map<String, Object> listAllWithMapView(@RequestParam(value = "key", requi
public BaseResponse<Object> getBy(@PathVariable("key") String key) {
return BaseResponse.ok(HttpStatus.OK.getReasonPhrase(), optionService.getByKey(key).orElse(null));
}


@GetMapping("comment")
@ApiOperation("Options for comment")
public Map<String, Object> comment() {
List<String> keys = new ArrayList<>();
keys.add("comment_gavatar_default");
keys.add("comment_content_placeholder");
return optionService.listOptions(keys);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ public BasePostDetailDTO getBy(@PathVariable("postId") Integer postId,
public Page<CommentWithHasChildrenVO> listTopComments(@PathVariable("postId") Integer postId,
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
return postCommentService.pageTopCommentsBy(postId, CommentStatus.PUBLISHED, PageRequest.of(page, optionService.getCommentPageSize(), sort));

Page<CommentWithHasChildrenVO> result = postCommentService.pageTopCommentsBy(postId, CommentStatus.PUBLISHED, PageRequest.of(page, optionService.getCommentPageSize(), sort));

return postCommentService.filterIpAddress(result);
}


Expand All @@ -94,23 +97,28 @@ public List<BaseCommentDTO> listChildrenBy(@PathVariable("postId") Integer postI
// Find all children comments
List<PostComment> postComments = postCommentService.listChildrenBy(postId, commentParentId, CommentStatus.PUBLISHED, sort);
// Convert to base comment dto
return postCommentService.convertTo(postComments);

List<BaseCommentDTO> result = postCommentService.convertTo(postComments);

return postCommentService.filterIpAddress(result);
}

@GetMapping("{postId:\\d+}/comments/tree_view")
@ApiOperation("Lists comments with tree view")
public Page<BaseCommentVO> listCommentsTree(@PathVariable("postId") Integer postId,
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
return postCommentService.pageVosBy(postId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
Page<BaseCommentVO> result = postCommentService.pageVosBy(postId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
return postCommentService.filterIpAddress(result);
}

@GetMapping("{postId:\\d+}/comments/list_view")
@ApiOperation("Lists comment with list view")
public Page<BaseCommentWithParentVO> listComments(@PathVariable("postId") Integer postId,
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
return postCommentService.pageWithParentVoBy(postId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
Page<BaseCommentWithParentVO> result = postCommentService.pageWithParentVoBy(postId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
return postCommentService.filterIpAddress(result);
}

@PostMapping("comments")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
import org.springframework.web.bind.annotation.*;
import run.halo.app.cache.lock.CacheLock;
import run.halo.app.model.dto.BaseCommentDTO;
import run.halo.app.model.entity.SheetComment;
import run.halo.app.model.enums.CommentStatus;
import run.halo.app.model.params.SheetCommentParam;
import run.halo.app.model.vo.BaseCommentVO;
import run.halo.app.model.vo.BaseCommentWithParentVO;
import run.halo.app.model.vo.CommentWithHasChildrenVO;
import run.halo.app.service.OptionService;
import run.halo.app.service.SheetCommentService;
import run.halo.app.service.SheetService;

import java.util.List;

import static org.springframework.data.domain.Sort.Direction.DESC;

/**
Expand All @@ -39,21 +44,42 @@ public SheetController(SheetService sheetService, SheetCommentService sheetComme
this.optionService = optionService;
}

@GetMapping("{sheetId:\\d+}/comments/top_view")
public Page<CommentWithHasChildrenVO> listTopComments(@PathVariable("sheetId") Integer sheetId,
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
Page<CommentWithHasChildrenVO> result = sheetCommentService.pageTopCommentsBy(sheetId, CommentStatus.PUBLISHED, PageRequest.of(page, optionService.getCommentPageSize(), sort));
return sheetCommentService.filterIpAddress(result);
}

@GetMapping("{sheetId:\\d+}/comments/{commentParentId:\\d+}/children")
public List<BaseCommentDTO> listChildrenBy(@PathVariable("sheetId") Integer sheetId,
@PathVariable("commentParentId") Long commentParentId,
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
// Find all children comments
List<SheetComment> sheetComments = sheetCommentService.listChildrenBy(sheetId, commentParentId, CommentStatus.PUBLISHED, sort);
// Convert to base comment dto
List<BaseCommentDTO> result = sheetCommentService.convertTo(sheetComments);
return sheetCommentService.filterIpAddress(result);
}


@GetMapping("{sheetId:\\d+}/comments/tree_view")
@ApiOperation("Lists comments with tree view")
public Page<BaseCommentVO> listCommentsTree(@PathVariable("sheetId") Integer sheetId,
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
return sheetCommentService.pageVosBy(sheetId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
Page<BaseCommentVO> result = sheetCommentService.pageVosBy(sheetId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
return sheetCommentService.filterIpAddress(result);
}

@GetMapping("{sheetId:\\d+}/comments/list_view")
@ApiOperation("Lists comment with list view")
public Page<BaseCommentWithParentVO> listComments(@PathVariable("sheetId") Integer sheetId,
@RequestParam(name = "page", required = false, defaultValue = "0") int page,
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
return sheetCommentService.pageWithParentVoBy(sheetId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
Page<BaseCommentWithParentVO> result = sheetCommentService.pageWithParentVoBy(sheetId, PageRequest.of(page, optionService.getCommentPageSize(), sort));
return sheetCommentService.filterIpAddress(result);
}

@PostMapping("comments")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ public String handleError(HttpServletRequest request) {
}
}

if (statusCode == 500) {
return "redirect:/500";
} else {
return "redirect:/404";
}
return statusCode == 500 ? "redirect:/500" : "redirect:/404";
}

/**
Expand Down
Loading

0 comments on commit d6bfa07

Please sign in to comment.