Merge pull request #167 from halo-dev/dev

Dev
pull/172/head
John Niang 2019-05-25 07:27:23 +08:00 committed by GitHub
commit 8508a374e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
113 changed files with 593 additions and 345 deletions

View File

@ -1,4 +1,4 @@
FROM openjdk:8-jdk-alpine FROM openjdk:8-jre-alpine
VOLUME /tmp VOLUME /tmp

View File

@ -1,13 +1,12 @@
<h1 align="center"><a href="https://github.com/halo-dev" target="_blank">Halo</a></h1> <h1 align="center"><a href="https://github.com/halo-dev" target="_blank">Halo</a></h1>
> Halo 可能是最好的 Java 博客系统 > Halo 是一款现代化的个人独立博客系统,给习惯写博客的同学一个更好的选择
<p align="center"> <p align="center">
<a href="https://ryanc.cc"><img alt="Author" src="https://img.shields.io/badge/author-ruibaby-red.svg?style=flat-square"/></a> <a href="https://ryanc.cc"><img alt="Author" src="https://img.shields.io/badge/author-ruibaby-red.svg?style=flat-square"/></a>
<a href="#"><img alt="JDK" src="https://img.shields.io/badge/JDK-1.8-yellow.svg?style=flat-square"/></a> <a href="#"><img alt="JDK" src="https://img.shields.io/badge/JDK-1.8-yellow.svg?style=flat-square"/></a>
<a href="https://github.com/halo-dev/halo/releases"><img alt="GitHub release" src="https://img.shields.io/github/release/halo-dev/halo.svg?style=flat-square"/></a> <a href="https://github.com/halo-dev/halo/releases"><img alt="GitHub release" src="https://img.shields.io/github/release/halo-dev/halo.svg?style=flat-square"/></a>
<a href="https://travis-ci.org/halo-dev/halo"><img alt="Travis CI" src="https://img.shields.io/travis/halo-dev/halo.svg?style=flat-square"/></a> <a href="https://travis-ci.org/halo-dev/halo"><img alt="Travis CI" src="https://img.shields.io/travis/halo-dev/halo.svg?style=flat-square"/></a>
<a href="https://hub.docker.com/r/halo-dev/halo/"><img alt="Docker Build Status" src="https://img.shields.io/docker/build/halo-dev/halo.svg?style=flat-square"/></a>
</p> </p>
------------------------------ ------------------------------
@ -32,28 +31,13 @@
## 博客示例 ## 博客示例
[Ryan0up'S Blog](https://ryanc.cc) 请看 <[https://github.com/halo-dev/halo/issues/26](https://github.com/halo-dev/halo/issues/26)>。
[SNAIL BLOG](https://slogc.cc) ## 周边
[宋浩志博客](http://songhaozhi.com) - 后台管理源码:<[https://github.com/halo-dev/halo-admin](https://github.com/halo-dev/halo-admin)>
- 主题仓库:<[https://halo.run/theme](https://halo.run/theme)>
[KingYiFan'S Blog](https://blog.cnbuilder.cn) - 管理 APP<[https://github.com/halo-dev/halo-app](https://github.com/halo-dev/halo-app)>
[AquanBlog](https://blog.eunji.cn/)
## 主题
除了内置的 [Anatole](https://github.com/hi-caicai/farbox-theme-Anatole) 和 [Material](https://github.com/viosey/hexo-theme-material) ,还有下列主题没有集成在项目里,如有需要,请自行下载之后通过后台上传上去使用。
- [Vno](https://github.com/halo-dev/vno-halo) - 来自 Jekyll 的一款主题,作者 [Wei Wang](https://onevcat.com/)。
- [Hux](https://github.com/halo-dev/hux-halo) - 来自 Jekyll 的一款主题,作者 [Xuan Huang](https://huangxuan.me/)。
- [Story](https://github.com/halo-dev/story-halo) - 来自 Typecho 的一款主题,作者 [Trii Hsia](https://yumoe.com/)。
- [NexT](https://github.com/halo-dev/next-halo) - 来自 Hexo 的一款主题,作者 [iissnan](https://notes.iissnan.com/)。
- [Casper](https://github.com/halo-dev/casper-halo) - 来自 Ghost 的一款主题,作者 [Ghost](https://github.com/TryGhost)。
- [Pinghsu](https://github.com/halo-dev/pinghsu-halo) - 来自 Typecho 的一款主题,作者 [Chakhsu.Lau](https://github.com/chakhsu)。
> 声明:不接受任何对**移植主题**功能上的意见和建议。
## 许可证 ## 许可证

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip

View File

@ -1,12 +1,12 @@
package run.halo.app; package run.halo.app;
import org.springframework.scheduling.annotation.EnableAsync;
import run.halo.app.repository.base.BaseRepositoryImpl;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import run.halo.app.repository.base.BaseRepositoryImpl;
/** /**
* <pre> * <pre>

View File

@ -94,6 +94,12 @@ public class InMemoryCacheStore extends StringCacheStore {
log.debug("Removed key: [{}]", key); log.debug("Removed key: [{}]", key);
} }
@PreDestroy
public void preDestroy() {
log.debug("Cancelling all timer tasks");
timer.cancel();
}
/** /**
* Cache cleaner. * Cache cleaner.
* *
@ -111,10 +117,4 @@ public class InMemoryCacheStore extends StringCacheStore {
}); });
} }
} }
@PreDestroy
public void preDestroy() {
log.debug("Cancelling all timer tasks");
timer.cancel();
}
} }

View File

@ -8,7 +8,6 @@ import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.http.HttpMethod;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
@ -114,7 +113,7 @@ public class HaloConfiguration {
ApiAuthenticationFilter apiFilter = new ApiAuthenticationFilter(haloProperties, optionService); ApiAuthenticationFilter apiFilter = new ApiAuthenticationFilter(haloProperties, optionService);
apiFilter.addExcludeUrlPatterns( apiFilter.addExcludeUrlPatterns(
"/api/content/*/comments", "/api/content/*/comments",
"/api/content/**/comments/*" "/api/content/**/comments/**"
); );
DefaultAuthenticationFailureHandler failureHandler = new DefaultAuthenticationFailureHandler(); DefaultAuthenticationFailureHandler failureHandler = new DefaultAuthenticationFailureHandler();

View File

@ -3,7 +3,6 @@ package run.halo.app.config;
import com.fasterxml.classmate.TypeResolver; import com.fasterxml.classmate.TypeResolver;
import io.swagger.models.auth.In; import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
@ -57,7 +56,7 @@ public class SwaggerConfiguration {
new ResponseMessageBuilder().code(404).message("Not found").build(), new ResponseMessageBuilder().code(404).message("Not found").build(),
new ResponseMessageBuilder().code(500).message("Internal server error").build()); new ResponseMessageBuilder().code(500).message("Internal server error").build());
public SwaggerConfiguration( HaloProperties haloProperties) { public SwaggerConfiguration(HaloProperties haloProperties) {
this.haloProperties = haloProperties; this.haloProperties = haloProperties;
} }

View File

@ -45,7 +45,7 @@ public class LogController {
} }
@GetMapping @GetMapping
public Page<LogDTO> pageBy(@PageableDefault(sort = "updateTime", direction = DESC) Pageable pageable){ public Page<LogDTO> pageBy(@PageableDefault(sort = "updateTime", direction = DESC) Pageable pageable) {
Page<Log> logPage = logService.listAll(pageable); Page<Log> logPage = logService.listAll(pageable);
return logPage.map(log -> new LogDTO().convertFrom(log)); return logPage.map(log -> new LogDTO().convertFrom(log));
} }

View File

@ -4,10 +4,7 @@ import io.swagger.annotations.ApiOperation;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import run.halo.app.model.dto.OptionDTO; import run.halo.app.model.dto.OptionDTO;
import run.halo.app.model.params.MailParam;
import run.halo.app.model.params.OptionParam; import run.halo.app.model.params.OptionParam;
import run.halo.app.model.support.BaseResponse;
import run.halo.app.service.MailService;
import run.halo.app.service.OptionService; import run.halo.app.service.OptionService;
import javax.validation.Valid; import javax.validation.Valid;

View File

@ -1,6 +1,5 @@
package run.halo.app.controller.base; package run.halo.app.controller.base;
import run.halo.app.model.support.BaseResponse;
import org.springframework.core.MethodParameter; import org.springframework.core.MethodParameter;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;

View File

@ -1,16 +1,12 @@
package run.halo.app.controller.base; package run.halo.app.controller.base;
import org.springframework.web.HttpMediaTypeNotAcceptableException;
import run.halo.app.exception.HaloException;
import run.halo.app.model.support.BaseResponse;
import run.halo.app.utils.ExceptionUtils;
import run.halo.app.utils.ValidationUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.web.HttpMediaTypeNotAcceptableException;
import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.MissingServletRequestParameterException; import org.springframework.web.bind.MissingServletRequestParameterException;

View File

@ -33,15 +33,11 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
@Controller @Controller
public class ContentFeedController { public class ContentFeedController {
private final PostService postService;
private final OptionService optionService;
private final FreeMarkerConfigurer freeMarker;
private final static String UTF_8_SUFFIX = ";charset=UTF-8"; private final static String UTF_8_SUFFIX = ";charset=UTF-8";
private final static String XML_MEDIA_TYPE = MediaType.APPLICATION_XML_VALUE + UTF_8_SUFFIX; private final static String XML_MEDIA_TYPE = MediaType.APPLICATION_XML_VALUE + UTF_8_SUFFIX;
private final PostService postService;
private final OptionService optionService;
private final FreeMarkerConfigurer freeMarker;
public ContentFeedController(PostService postService, public ContentFeedController(PostService postService,
OptionService optionService, OptionService optionService,

View File

@ -59,8 +59,16 @@ public class MainController {
@GetMapping("/logo") @GetMapping("/logo")
public void logo(HttpServletResponse response) throws IOException { public void logo(HttpServletResponse response) throws IOException {
String blogLogo = optionService.getByProperty(BlogProperties.BLOG_LOGO).orElse("").toString(); String blogLogo = optionService.getByProperty(BlogProperties.BLOG_LOGO).orElse("").toString();
if(StringUtils.isNotEmpty(blogLogo)){ if (StringUtils.isNotEmpty(blogLogo)) {
response.sendRedirect(blogLogo); response.sendRedirect(blogLogo);
} }
} }
@GetMapping("/favicon.ico")
public void favicon(HttpServletResponse response) throws IOException {
String favicon = optionService.getByProperty(BlogProperties.BLOG_FAVICON).orElse("").toString();
if (StringUtils.isNotEmpty(favicon)) {
response.sendRedirect(favicon);
}
}
} }

View File

@ -1,11 +1,11 @@
package run.halo.app.controller.content.api; package run.halo.app.controller.content.api;
import run.halo.app.model.vo.ArchiveMonthVO;
import run.halo.app.model.vo.ArchiveYearVO;
import run.halo.app.service.PostService;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import run.halo.app.model.vo.ArchiveMonthVO;
import run.halo.app.model.vo.ArchiveYearVO;
import run.halo.app.service.PostService;
import java.util.List; import java.util.List;

View File

@ -1,7 +1,5 @@
package run.halo.app.controller.content.api; package run.halo.app.controller.content.api;
import run.halo.app.model.vo.LinkTeamVO;
import run.halo.app.service.LinkService;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;

View File

@ -1,13 +1,13 @@
package run.halo.app.controller.content.api; package run.halo.app.controller.content.api;
import run.halo.app.model.dto.MenuDTO;
import run.halo.app.service.MenuService;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.web.SortDefault; import org.springframework.data.web.SortDefault;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import run.halo.app.model.dto.MenuDTO;
import run.halo.app.service.MenuService;
import java.util.List; import java.util.List;

View File

@ -1,12 +1,12 @@
package run.halo.app.controller.content.api; package run.halo.app.controller.content.api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import run.halo.app.model.dto.OptionDTO; import run.halo.app.model.dto.OptionDTO;
import run.halo.app.model.support.BaseResponse; import run.halo.app.model.support.BaseResponse;
import run.halo.app.service.OptionService; import run.halo.app.service.OptionService;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;

View File

@ -97,7 +97,6 @@ public class PostController {
return postCommentService.convertTo(postComments); return postCommentService.convertTo(postComments);
} }
@GetMapping("{postId:\\d+}/comments/tree_view") @GetMapping("{postId:\\d+}/comments/tree_view")
@ApiOperation("Lists comments with tree view") @ApiOperation("Lists comments with tree view")
public Page<BaseCommentVO> listCommentsTree(@PathVariable("postId") Integer postId, public Page<BaseCommentVO> listCommentsTree(@PathVariable("postId") Integer postId,

View File

@ -1,11 +1,11 @@
package run.halo.app.controller.content.api; package run.halo.app.controller.content.api;
import run.halo.app.model.dto.UserDTO;
import run.halo.app.service.UserService;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import run.halo.app.model.dto.UserDTO;
import run.halo.app.service.UserService;
/** /**
* Portal user controller. * Portal user controller.
@ -26,6 +26,6 @@ public class UserController {
@GetMapping("profile") @GetMapping("profile")
@ApiOperation("Gets blogger profile") @ApiOperation("Gets blogger profile")
public UserDTO getProfile() { public UserDTO getProfile() {
return userService.getCurrentUser().map(user -> new UserDTO().<UserDTO>convertFrom(user)).get(); return userService.getCurrentUser().map(user -> (UserDTO) new UserDTO().convertFrom(user)).get();
} }
} }

View File

@ -75,7 +75,7 @@ public class CommonController implements ErrorController {
return "common/error/404"; return "common/error/404";
} }
StrBuilder path = new StrBuilder("themes/"); StrBuilder path = new StrBuilder("themes/");
path.append(themeService.getActivatedThemeId()); path.append(themeService.getActivatedTheme().getFolderName());
path.append("/404"); path.append("/404");
return path.toString(); return path.toString();
} }
@ -91,7 +91,7 @@ public class CommonController implements ErrorController {
return "common/error/500"; return "common/error/500";
} }
StrBuilder path = new StrBuilder("themes/"); StrBuilder path = new StrBuilder("themes/");
path.append(themeService.getActivatedThemeId()); path.append(themeService.getActivatedTheme().getFolderName());
path.append("/500"); path.append("/500");
return path.toString(); return path.toString();
} }

View File

@ -1,6 +1,5 @@
package run.halo.app.controller.support; package run.halo.app.controller.support;
import run.halo.app.model.support.CommentPage;
import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.SerializerProvider;

View File

@ -70,7 +70,7 @@ public class CommentEventListener {
Map<String, Object> data = new HashMap<>(); Map<String, Object> data = new HashMap<>();
if (newEvent.getSource() instanceof PostService) { if (newEvent.getSource() instanceof PostCommentService) {
// Get postComment id // Get postComment id
PostComment postComment = postCommentService.getById(newEvent.getCommentId()); PostComment postComment = postCommentService.getById(newEvent.getCommentId());
@ -85,7 +85,7 @@ public class CommentEventListener {
data.put("page", post.getTitle()); data.put("page", post.getTitle());
data.put("author", postComment.getAuthor()); data.put("author", postComment.getAuthor());
data.put("content", postComment.getContent()); data.put("content", postComment.getContent());
} else if (newEvent.getSource() instanceof SheetService) { } else if (newEvent.getSource() instanceof SheetCommentService) {
SheetComment sheetComment = sheetCommentService.getById(newEvent.getCommentId()); SheetComment sheetComment = sheetCommentService.getById(newEvent.getCommentId());
log.debug("Got sheet comment: [{}]", sheetComment); log.debug("Got sheet comment: [{}]", sheetComment);
@ -99,7 +99,7 @@ public class CommentEventListener {
data.put("page", sheet.getTitle()); data.put("page", sheet.getTitle());
data.put("author", sheetComment.getAuthor()); data.put("author", sheetComment.getAuthor());
data.put("content", sheetComment.getContent()); data.put("content", sheetComment.getContent());
} else if (newEvent.getSource() instanceof JournalService) { } else if (newEvent.getSource() instanceof JournalCommentService) {
JournalComment journalComment = journalCommentService.getById(newEvent.getCommentId()); JournalComment journalComment = journalCommentService.getById(newEvent.getCommentId());
log.debug("Got journal comment: [{}]", journalComment); log.debug("Got journal comment: [{}]", journalComment);

View File

@ -78,6 +78,7 @@ public class FreemarkerConfigAwareListener {
log.debug("Received option updated event"); log.debug("Received option updated event");
loadOptionsConfig(); loadOptionsConfig();
loadThemeConfig();
} }

View File

@ -1,9 +1,6 @@
package run.halo.app.event.theme; package run.halo.app.event.theme;
import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEvent;
import org.springframework.lang.NonNull;
import org.springframework.util.Assert;
import run.halo.app.handler.theme.config.support.ThemeProperty;
/** /**
* Theme activated event. * Theme activated event.

View File

@ -1,7 +1,6 @@
package run.halo.app.event.theme; package run.halo.app.event.theme;
import org.springframework.context.event.EventListener; import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import run.halo.app.cache.StringCacheStore; import run.halo.app.cache.StringCacheStore;
import run.halo.app.event.options.OptionUpdatedEvent; import run.halo.app.event.options.OptionUpdatedEvent;

View File

@ -1,10 +1,10 @@
package run.halo.app.filter; package run.halo.app.filter;
import run.halo.app.security.filter.AdminAuthenticationFilter;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.web.cors.CorsUtils; import org.springframework.web.cors.CorsUtils;
import org.springframework.web.filter.GenericFilterBean; import org.springframework.web.filter.GenericFilterBean;
import run.halo.app.security.filter.AdminAuthenticationFilter;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
import javax.servlet.ServletException; import javax.servlet.ServletException;

View File

@ -22,6 +22,39 @@ public interface FileHandler {
MediaType IMAGE_TYPE = MediaType.valueOf("image/*"); MediaType IMAGE_TYPE = MediaType.valueOf("image/*");
/**
* Check whether media type provided is an image type.
*
* @param mediaType media type provided
* @return true if it is an image type
*/
static boolean isImageType(@Nullable String mediaType) {
return mediaType != null && IMAGE_TYPE.includes(MediaType.valueOf(mediaType));
}
/**
* Check whether media type provided is an image type.
*
* @param mediaType media type provided
* @return true if it is an image type
*/
static boolean isImageType(@Nullable MediaType mediaType) {
return mediaType != null && IMAGE_TYPE.includes(mediaType);
}
/**
* Normalize directory full name, ensure the end path separator.
*
* @param dir directory full name must not be blank
* @return normalized directory full name with end path separator
*/
@NonNull
static String normalizeDirectory(@NonNull String dir) {
Assert.hasText(dir, "Directory full name must not be blank");
return StringUtils.appendIfMissing(dir, FILE_SEPARATOR);
}
/** /**
* Uploads file. * Uploads file.
* *
@ -47,39 +80,4 @@ public interface FileHandler {
* @return true if supported; false or else * @return true if supported; false or else
*/ */
boolean supportType(@Nullable AttachmentType type); boolean supportType(@Nullable AttachmentType type);
/**
* Check whether media type provided is an image type.
*
* @param mediaType media type provided
* @return true if it is an image type
*/
static boolean isImageType(@Nullable String mediaType) {
return mediaType != null && IMAGE_TYPE.includes(MediaType.valueOf(mediaType));
}
/**
* Check whether media type provided is an image type.
*
* @param mediaType media type provided
* @return true if it is an image type
*/
static boolean isImageType(@Nullable MediaType mediaType) {
return mediaType != null && IMAGE_TYPE.includes(mediaType);
}
/**
* Normalize directory full name, ensure the end path separator.
*
* @param dir directory full name must not be blank
* @return normalized directory full name with end path separator
*/
@NonNull
static String normalizeDirectory(@NonNull String dir) {
Assert.hasText(dir, "Directory full name must not be blank");
return StringUtils.appendIfMissing(dir, FILE_SEPARATOR);
}
} }

View File

@ -1,9 +1,5 @@
package run.halo.app.handler.file; package run.halo.app.handler.file;
import run.halo.app.exception.FileOperationException;
import run.halo.app.model.entity.Attachment;
import run.halo.app.model.enums.AttachmentType;
import run.halo.app.model.support.UploadResult;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.lang.NonNull; import org.springframework.lang.NonNull;
@ -12,6 +8,10 @@ import org.springframework.stereotype.Component;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import run.halo.app.exception.FileOperationException;
import run.halo.app.model.entity.Attachment;
import run.halo.app.model.enums.AttachmentType;
import run.halo.app.model.support.UploadResult;
import java.util.Collection; import java.util.Collection;
import java.util.LinkedList; import java.util.LinkedList;

View File

@ -1,5 +1,12 @@
package run.halo.app.handler.file; package run.halo.app.handler.file;
import lombok.extern.slf4j.Slf4j;
import net.coobird.thumbnailator.Thumbnails;
import org.springframework.http.MediaType;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.web.multipart.MultipartFile;
import run.halo.app.config.properties.HaloProperties; import run.halo.app.config.properties.HaloProperties;
import run.halo.app.exception.FileOperationException; import run.halo.app.exception.FileOperationException;
import run.halo.app.exception.ServiceException; import run.halo.app.exception.ServiceException;
@ -8,13 +15,6 @@ import run.halo.app.model.support.UploadResult;
import run.halo.app.service.OptionService; import run.halo.app.service.OptionService;
import run.halo.app.utils.FilenameUtils; import run.halo.app.utils.FilenameUtils;
import run.halo.app.utils.HaloUtils; import run.halo.app.utils.HaloUtils;
import lombok.extern.slf4j.Slf4j;
import net.coobird.thumbnailator.Thumbnails;
import org.springframework.http.MediaType;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.web.multipart.MultipartFile;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;

View File

@ -115,6 +115,7 @@ public class YamlThemeConfigResolverImpl implements ThemeConfigResolver {
item.setDataType(DataType.typeOf(dataType)); item.setDataType(DataType.typeOf(dataType));
item.setType(InputType.typeOf(itemMap.get("type"))); item.setType(InputType.typeOf(itemMap.get("type")));
item.setDefaultValue(itemMap.get("default")); item.setDefaultValue(itemMap.get("default"));
item.setPlaceholder(itemMap.getOrDefault("placeholder", "").toString());
// Handle options // Handle options
item.setOptions(handleOptions(itemMap.get("options"))); item.setOptions(handleOptions(itemMap.get("options")));
@ -140,6 +141,7 @@ public class YamlThemeConfigResolverImpl implements ThemeConfigResolver {
item.setDataType(DataType.typeOf(dataType)); item.setDataType(DataType.typeOf(dataType));
item.setType(InputType.typeOf(itemMap.get("type"))); item.setType(InputType.typeOf(itemMap.get("type")));
item.setDefaultValue(itemMap.get("default")); item.setDefaultValue(itemMap.get("default"));
item.setPlaceholder(itemMap.getOrDefault("placeholder", "").toString());
// Handle options // Handle options
item.setOptions(handleOptions(itemMap.get("options"))); item.setOptions(handleOptions(itemMap.get("options")));

View File

@ -41,6 +41,11 @@ public class Item {
*/ */
private Object defaultValue; private Object defaultValue;
/**
* Text item placeholder.
*/
private String placeholder;
/** /**
* Item's options, default is empty list * Item's options, default is empty list
*/ */

View File

@ -73,6 +73,19 @@ public class ThemeProperty {
*/ */
private String screenshots; private String screenshots;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ThemeProperty that = (ThemeProperty) o;
return id.equals(that.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
@Data @Data
public static class Author { public static class Author {
@ -91,17 +104,4 @@ public class ThemeProperty {
*/ */
private String avatar; private String avatar;
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ThemeProperty that = (ThemeProperty) o;
return id.equals(that.id);
}
@Override
public int hashCode() {
return Objects.hash(id);
}
} }

View File

@ -1,6 +1,5 @@
package run.halo.app.listener; package run.halo.app.listener;
import com.sun.nio.zipfs.JarFileSystemProvider;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationStartedEvent; import org.springframework.boot.context.event.ApplicationStartedEvent;
@ -10,20 +9,15 @@ import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.util.ResourceUtils; import org.springframework.util.ResourceUtils;
import run.halo.app.config.properties.HaloProperties; import run.halo.app.config.properties.HaloProperties;
import run.halo.app.model.entity.User;
import run.halo.app.model.params.UserParam;
import run.halo.app.model.properties.PrimaryProperties; import run.halo.app.model.properties.PrimaryProperties;
import run.halo.app.model.support.CreateCheck;
import run.halo.app.service.OptionService; import run.halo.app.service.OptionService;
import run.halo.app.service.ThemeService; import run.halo.app.service.ThemeService;
import run.halo.app.service.UserService; import run.halo.app.service.UserService;
import run.halo.app.utils.FileUtils; import run.halo.app.utils.FileUtils;
import run.halo.app.utils.ValidationUtils;
import java.net.URI; import java.net.URI;
import java.nio.file.*; import java.nio.file.*;
import java.util.Collections; import java.util.Collections;
import java.util.List;
/** /**
* The method executed after the application is started. * The method executed after the application is started.

View File

@ -1,9 +1,9 @@
package run.halo.app.model.dto; package run.halo.app.model.dto;
import lombok.Data;
import run.halo.app.model.dto.base.OutputConverter; import run.halo.app.model.dto.base.OutputConverter;
import run.halo.app.model.entity.Attachment; import run.halo.app.model.entity.Attachment;
import run.halo.app.model.enums.AttachmentType; import run.halo.app.model.enums.AttachmentType;
import lombok.Data;
import java.util.Date; import java.util.Date;

View File

@ -1,10 +1,12 @@
package run.halo.app.model.dto; package run.halo.app.model.dto;
import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
import run.halo.app.model.dto.base.OutputConverter; import run.halo.app.model.dto.base.OutputConverter;
import run.halo.app.model.entity.Category; import run.halo.app.model.entity.Category;
import lombok.Data;
import java.util.Date;
/** /**
* Category output dto. * Category output dto.
@ -26,4 +28,6 @@ public class CategoryDTO implements OutputConverter<CategoryDTO, Category> {
private String description; private String description;
private Integer parentId; private Integer parentId;
private Date createTime;
} }

View File

@ -1,8 +1,8 @@
package run.halo.app.model.dto; package run.halo.app.model.dto;
import lombok.Data;
import run.halo.app.model.dto.base.OutputConverter; import run.halo.app.model.dto.base.OutputConverter;
import run.halo.app.model.entity.Link; import run.halo.app.model.entity.Link;
import lombok.Data;
/** /**
* Link output dto. * Link output dto.

View File

@ -1,11 +1,11 @@
package run.halo.app.model.dto; package run.halo.app.model.dto;
import run.halo.app.model.dto.base.OutputConverter;
import run.halo.app.model.entity.Log;
import run.halo.app.model.enums.LogType;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
import run.halo.app.model.dto.base.OutputConverter;
import run.halo.app.model.entity.Log;
import run.halo.app.model.enums.LogType;
import java.util.Date; import java.util.Date;

View File

@ -1,8 +1,8 @@
package run.halo.app.model.dto; package run.halo.app.model.dto;
import lombok.Data;
import run.halo.app.model.dto.base.OutputConverter; import run.halo.app.model.dto.base.OutputConverter;
import run.halo.app.model.entity.Menu; import run.halo.app.model.entity.Menu;
import lombok.Data;
/** /**
* Menu output dto. * Menu output dto.

View File

@ -1,8 +1,8 @@
package run.halo.app.model.dto; package run.halo.app.model.dto;
import lombok.Data;
import run.halo.app.model.dto.base.OutputConverter; import run.halo.app.model.dto.base.OutputConverter;
import run.halo.app.model.entity.Photo; import run.halo.app.model.entity.Photo;
import lombok.Data;
import java.util.Date; import java.util.Date;

View File

@ -1,8 +1,10 @@
package run.halo.app.model.dto; package run.halo.app.model.dto;
import lombok.Data;
import run.halo.app.model.dto.base.OutputConverter; import run.halo.app.model.dto.base.OutputConverter;
import run.halo.app.model.entity.Tag; import run.halo.app.model.entity.Tag;
import lombok.Data;
import java.util.Date;
/** /**
* Tag output dto. * Tag output dto.
@ -18,4 +20,6 @@ public class TagDTO implements OutputConverter<TagDTO, Tag> {
private String name; private String name;
private String slugName; private String slugName;
private Date createTime;
} }

View File

@ -1,10 +1,10 @@
package run.halo.app.model.dto; package run.halo.app.model.dto;
import run.halo.app.model.dto.base.OutputConverter;
import run.halo.app.model.entity.User;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
import run.halo.app.model.dto.base.OutputConverter;
import run.halo.app.model.entity.User;
import java.util.Date; import java.util.Date;

View File

@ -1,7 +1,6 @@
package run.halo.app.model.entity; package run.halo.app.model.entity;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
import javax.persistence.*; import javax.persistence.*;

View File

@ -1,7 +1,6 @@
package run.halo.app.model.entity; package run.halo.app.model.entity;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
import javax.persistence.*; import javax.persistence.*;

View File

@ -29,12 +29,6 @@ public enum DataType implements ValueEnum<Integer> {
this.value = value; this.value = value;
} }
@Override
public Integer getValue() {
return value;
}
/** /**
* Data type of string. * Data type of string.
* *
@ -53,6 +47,11 @@ public enum DataType implements ValueEnum<Integer> {
return STRING; return STRING;
} }
@Override
public Integer getValue() {
return value;
}
/** /**
* Converts data to corresponding type. * Converts data to corresponding type.
* *

View File

@ -12,13 +12,6 @@ import java.util.stream.Stream;
*/ */
public interface ValueEnum<T> { public interface ValueEnum<T> {
/**
* Gets enum value.
*
* @return enum value
*/
T getValue();
/** /**
* Converts value to corresponding enum. * Converts value to corresponding enum.
* *
@ -39,4 +32,11 @@ public interface ValueEnum<T> {
.orElseThrow(() -> new IllegalArgumentException("unknown database value: " + value)); .orElseThrow(() -> new IllegalArgumentException("unknown database value: " + value));
} }
/**
* Gets enum value.
*
* @return enum value
*/
T getValue();
} }

View File

@ -1,6 +1,5 @@
package run.halo.app.model.enums.converter; package run.halo.app.model.enums.converter;
import run.halo.app.model.enums.AttachmentType;
import run.halo.app.model.enums.AttachmentType; import run.halo.app.model.enums.AttachmentType;
import javax.persistence.Converter; import javax.persistence.Converter;

View File

@ -25,7 +25,7 @@ public class MenuTagDirective implements TemplateDirectiveModel {
private final MenuService menuService; private final MenuService menuService;
public MenuTagDirective(Configuration configuration,MenuService menuService) { public MenuTagDirective(Configuration configuration, MenuService menuService) {
this.menuService = menuService; this.menuService = menuService;
configuration.setSharedVariable("menuTag", this); configuration.setSharedVariable("menuTag", this);
} }
@ -41,7 +41,7 @@ public class MenuTagDirective implements TemplateDirectiveModel {
env.setVariable("menus", builder.build().wrap(menuService.listAll())); env.setVariable("menus", builder.build().wrap(menuService.listAll()));
break; break;
case "tree": case "tree":
env.setVariable("menus",builder.build().wrap(menuService.listAsTree(Sort.by(DESC, "priority")))); env.setVariable("menus", builder.build().wrap(menuService.listAsTree(Sort.by(DESC, "priority"))));
break; break;
case "count": case "count":
env.setVariable("count", builder.build().wrap(menuService.count())); env.setVariable("count", builder.build().wrap(menuService.count()));

View File

@ -1,11 +1,11 @@
package run.halo.app.model.params; package run.halo.app.model.params;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import run.halo.app.model.dto.base.InputConverter; import run.halo.app.model.dto.base.InputConverter;
import run.halo.app.model.entity.Category; import run.halo.app.model.entity.Category;
import run.halo.app.utils.HaloUtils; import run.halo.app.utils.HaloUtils;
import run.halo.app.utils.SlugUtils; import run.halo.app.utils.SlugUtils;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;

View File

@ -1,9 +1,9 @@
package run.halo.app.model.params; package run.halo.app.model.params;
import run.halo.app.model.dto.base.InputConverter;
import run.halo.app.model.entity.Link;
import lombok.Data; import lombok.Data;
import org.hibernate.validator.constraints.URL; import org.hibernate.validator.constraints.URL;
import run.halo.app.model.dto.base.InputConverter;
import run.halo.app.model.entity.Link;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;

View File

@ -1,7 +1,6 @@
package run.halo.app.model.params; package run.halo.app.model.params;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import run.halo.app.model.dto.base.InputConverter; import run.halo.app.model.dto.base.InputConverter;

View File

@ -1,8 +1,8 @@
package run.halo.app.model.params; package run.halo.app.model.params;
import lombok.Data;
import run.halo.app.model.dto.base.InputConverter; import run.halo.app.model.dto.base.InputConverter;
import run.halo.app.model.entity.Option; import run.halo.app.model.entity.Option;
import lombok.Data;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;

View File

@ -1,13 +1,13 @@
package run.halo.app.model.params; package run.halo.app.model.params;
import cn.hutool.crypto.digest.BCrypt;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import run.halo.app.model.dto.base.InputConverter; import run.halo.app.model.dto.base.InputConverter;
import run.halo.app.model.entity.Post; import run.halo.app.model.entity.Post;
import run.halo.app.model.enums.PostCreateFrom; import run.halo.app.model.enums.PostCreateFrom;
import run.halo.app.model.enums.PostStatus; import run.halo.app.model.enums.PostStatus;
import run.halo.app.utils.HaloUtils; import run.halo.app.utils.HaloUtils;
import cn.hutool.crypto.digest.BCrypt;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import javax.validation.constraints.Min; import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;

View File

@ -1,11 +1,9 @@
package run.halo.app.model.params; package run.halo.app.model.params;
import run.halo.app.model.dto.base.InputConverter;
import run.halo.app.model.entity.Tag;
import run.halo.app.utils.HaloUtils;
import run.halo.app.utils.SlugUtils;
import lombok.Data; import lombok.Data;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import run.halo.app.model.dto.base.InputConverter;
import run.halo.app.model.entity.Tag;
import run.halo.app.utils.HaloUtils; import run.halo.app.utils.HaloUtils;
import run.halo.app.utils.SlugUtils; import run.halo.app.utils.SlugUtils;

View File

@ -51,4 +51,5 @@ public enum CommentProperties implements PropertyEnum {
@Override @Override
public String getValue() { public String getValue() {
return value; return value;
}} }
}

View File

@ -17,7 +17,7 @@ public enum OtherProperties implements PropertyEnum {
/** /**
* *
*/ */
SPIDER_DISABLED("spider_disabled",Boolean.class,"false"); SPIDER_DISABLED("spider_disabled", Boolean.class, "false");
private final String value; private final String value;

View File

@ -47,4 +47,5 @@ public enum SeoProperties implements PropertyEnum {
@Override @Override
public String getValue() { public String getValue() {
return value; return value;
}} }
}

View File

@ -20,11 +20,9 @@ public enum UpYunProperties implements PropertyEnum {
OSS_SMALL_URL("oss_upyun_small_url", String.class, ""); OSS_SMALL_URL("oss_upyun_small_url", String.class, "");
private String value;
private Class<?> type;
private final String defaultValue; private final String defaultValue;
private String value;
private Class<?> type;
UpYunProperties(String value, Class<?> type, String defaultValue) { UpYunProperties(String value, Class<?> type, String defaultValue) {
this.defaultValue = defaultValue; this.defaultValue = defaultValue;

View File

@ -1,9 +1,9 @@
package run.halo.app.model.vo; package run.halo.app.model.vo;
import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.ToString; import lombok.ToString;
import run.halo.app.model.dto.CategoryDTO; import run.halo.app.model.dto.CategoryDTO;
import lombok.Data;
import java.util.List; import java.util.List;

View File

@ -1,8 +1,8 @@
package run.halo.app.model.vo; package run.halo.app.model.vo;
import run.halo.app.model.dto.LinkDTO;
import lombok.Data; import lombok.Data;
import lombok.ToString; import lombok.ToString;
import run.halo.app.model.dto.LinkDTO;
import java.util.List; import java.util.List;

View File

@ -1,8 +1,8 @@
package run.halo.app.repository; package run.halo.app.repository;
import org.springframework.lang.NonNull;
import run.halo.app.model.entity.Category; import run.halo.app.model.entity.Category;
import run.halo.app.repository.base.BaseRepository; import run.halo.app.repository.base.BaseRepository;
import org.springframework.lang.NonNull;
import java.util.Optional; import java.util.Optional;

View File

@ -1,13 +1,8 @@
package run.halo.app.repository; package run.halo.app.repository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.lang.NonNull;
import run.halo.app.model.entity.JournalComment; import run.halo.app.model.entity.JournalComment;
import run.halo.app.model.projection.CommentCountProjection;
import run.halo.app.repository.base.BaseCommentRepository; import run.halo.app.repository.base.BaseCommentRepository;
import java.util.List;
/** /**
* Journal comment repository. * Journal comment repository.
* *

View File

@ -2,7 +2,6 @@ package run.halo.app.repository;
import run.halo.app.model.entity.Link; import run.halo.app.model.entity.Link;
import run.halo.app.repository.base.BaseRepository; import run.halo.app.repository.base.BaseRepository;
import run.halo.app.repository.base.BaseRepository;
/** /**
* Link repository. * Link repository.

View File

@ -1,11 +1,8 @@
package run.halo.app.repository; package run.halo.app.repository;
import org.springframework.lang.NonNull;
import run.halo.app.model.entity.Menu; import run.halo.app.model.entity.Menu;
import run.halo.app.repository.base.BaseRepository; import run.halo.app.repository.base.BaseRepository;
import org.springframework.lang.NonNull;
import run.halo.app.repository.base.BaseRepository;
import java.util.Optional;
/** /**
* Menu repository. * Menu repository.

View File

@ -2,7 +2,6 @@ package run.halo.app.repository;
import run.halo.app.model.entity.Option; import run.halo.app.model.entity.Option;
import run.halo.app.repository.base.BaseRepository; import run.halo.app.repository.base.BaseRepository;
import run.halo.app.repository.base.BaseRepository;
import java.util.Optional; import java.util.Optional;

View File

@ -1,13 +1,8 @@
package run.halo.app.repository; package run.halo.app.repository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.lang.NonNull;
import run.halo.app.model.entity.PostComment; import run.halo.app.model.entity.PostComment;
import run.halo.app.model.projection.CommentCountProjection;
import run.halo.app.repository.base.BaseCommentRepository; import run.halo.app.repository.base.BaseCommentRepository;
import java.util.List;
/** /**
* PostComment repository. * PostComment repository.
* *

View File

@ -1,10 +1,10 @@
package run.halo.app.repository; package run.halo.app.repository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.lang.NonNull;
import run.halo.app.model.entity.PostTag; import run.halo.app.model.entity.PostTag;
import run.halo.app.model.projection.TagPostPostCountProjection; import run.halo.app.model.projection.TagPostPostCountProjection;
import run.halo.app.repository.base.BaseRepository; import run.halo.app.repository.base.BaseRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.lang.NonNull;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;

View File

@ -1,13 +1,8 @@
package run.halo.app.repository; package run.halo.app.repository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.lang.NonNull;
import run.halo.app.model.entity.SheetComment; import run.halo.app.model.entity.SheetComment;
import run.halo.app.model.projection.CommentCountProjection;
import run.halo.app.repository.base.BaseCommentRepository; import run.halo.app.repository.base.BaseCommentRepository;
import java.util.List;
/** /**
* Sheet comment repository. * Sheet comment repository.
* *

View File

@ -1,8 +1,7 @@
package run.halo.app.repository; package run.halo.app.repository;
import run.halo.app.model.entity.Tag;
import run.halo.app.repository.base.BaseRepository;
import org.springframework.lang.NonNull; import org.springframework.lang.NonNull;
import run.halo.app.model.entity.Tag;
import run.halo.app.repository.base.BaseRepository; import run.halo.app.repository.base.BaseRepository;
import java.util.Optional; import java.util.Optional;

View File

@ -1,8 +1,7 @@
package run.halo.app.repository; package run.halo.app.repository;
import run.halo.app.model.entity.User;
import run.halo.app.repository.base.BaseRepository;
import org.springframework.lang.NonNull; import org.springframework.lang.NonNull;
import run.halo.app.model.entity.User;
import run.halo.app.repository.base.BaseRepository; import run.halo.app.repository.base.BaseRepository;
import java.util.Optional; import java.util.Optional;

View File

@ -40,6 +40,26 @@ public class BaseRepositoryImpl<DOMAIN, ID> extends SimpleJpaRepository<DOMAIN,
this.entityManager = entityManager; this.entityManager = entityManager;
} }
/**
* Executes a count query and transparently sums up all values returned.
*
* @param query must not be {@literal null}.
* @return
*/
private static long executeCountQuery(TypedQuery<Long> query) {
Assert.notNull(query, "TypedQuery must not be null!");
List<Long> totals = query.getResultList();
long total = 0L;
for (Long element : totals) {
total += element == null ? 0 : element;
}
return total;
}
/** /**
* Finds all domain by id list and the specified sort. * Finds all domain by id list and the specified sort.
* *
@ -140,24 +160,4 @@ public class BaseRepositoryImpl<DOMAIN, ID> extends SimpleJpaRepository<DOMAIN,
return path.in(this.parameter); return path.in(this.parameter);
} }
} }
/**
* Executes a count query and transparently sums up all values returned.
*
* @param query must not be {@literal null}.
* @return
*/
private static long executeCountQuery(TypedQuery<Long> query) {
Assert.notNull(query, "TypedQuery must not be null!");
List<Long> totals = query.getResultList();
long total = 0L;
for (Long element : totals) {
total += element == null ? 0 : element;
}
return total;
}
} }

View File

@ -1,7 +1,7 @@
package run.halo.app.security.authentication; package run.halo.app.security.authentication;
import run.halo.app.security.support.UserDetail;
import org.springframework.lang.NonNull; import org.springframework.lang.NonNull;
import run.halo.app.security.support.UserDetail;
/** /**
* Authentication. * Authentication.

View File

@ -1,6 +1,5 @@
package run.halo.app.security.context; package run.halo.app.security.context;
import run.halo.app.security.authentication.Authentication;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import run.halo.app.security.authentication.Authentication; import run.halo.app.security.authentication.Authentication;

View File

@ -1,6 +1,5 @@
package run.halo.app.security.context; package run.halo.app.security.context;
import run.halo.app.security.authentication.Authentication;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;

View File

@ -31,19 +31,15 @@ import java.util.Set;
*/ */
public abstract class AbstractAuthenticationFilter extends OncePerRequestFilter { public abstract class AbstractAuthenticationFilter extends OncePerRequestFilter {
protected final AntPathMatcher antPathMatcher;
protected final HaloProperties haloProperties;
protected final OptionService optionService;
private AuthenticationFailureHandler failureHandler; private AuthenticationFailureHandler failureHandler;
/** /**
* Exclude url patterns. * Exclude url patterns.
*/ */
private Set<String> excludeUrlPatterns = new HashSet<>(2); private Set<String> excludeUrlPatterns = new HashSet<>(2);
protected final AntPathMatcher antPathMatcher;
protected final HaloProperties haloProperties;
protected final OptionService optionService;
protected AbstractAuthenticationFilter(HaloProperties haloProperties, protected AbstractAuthenticationFilter(HaloProperties haloProperties,
OptionService optionService) { OptionService optionService) {
this.haloProperties = haloProperties; this.haloProperties = haloProperties;
@ -70,17 +66,6 @@ public abstract class AbstractAuthenticationFilter extends OncePerRequestFilter
return excludeUrlPatterns.stream().anyMatch(p -> antPathMatcher.match(p, request.getServletPath())); return excludeUrlPatterns.stream().anyMatch(p -> antPathMatcher.match(p, request.getServletPath()));
} }
/**
* Sets exclude url patterns.
*
* @param excludeUrlPatterns exclude urls
*/
public void setExcludeUrlPatterns(@NonNull Collection<String> excludeUrlPatterns) {
Assert.notNull(excludeUrlPatterns, "Exclude url patterns must not be null");
this.excludeUrlPatterns = new HashSet<>(excludeUrlPatterns);
}
/** /**
* Adds exclude url patterns. * Adds exclude url patterns.
* *
@ -102,6 +87,16 @@ public abstract class AbstractAuthenticationFilter extends OncePerRequestFilter
return excludeUrlPatterns; return excludeUrlPatterns;
} }
/**
* Sets exclude url patterns.
*
* @param excludeUrlPatterns exclude urls
*/
public void setExcludeUrlPatterns(@NonNull Collection<String> excludeUrlPatterns) {
Assert.notNull(excludeUrlPatterns, "Exclude url patterns must not be null");
this.excludeUrlPatterns = new HashSet<>(excludeUrlPatterns);
}
/** /**
* Gets authentication failure handler. (Default: @DefaultAuthenticationFailureHandler) * Gets authentication failure handler. (Default: @DefaultAuthenticationFailureHandler)

View File

@ -1,6 +1,5 @@
package run.halo.app.security.handler; package run.halo.app.security.handler;
import run.halo.app.exception.HaloException;
import run.halo.app.exception.HaloException; import run.halo.app.exception.HaloException;
import javax.servlet.ServletException; import javax.servlet.ServletException;

View File

@ -1,10 +1,5 @@
package run.halo.app.security.resolver; package run.halo.app.security.resolver;
import run.halo.app.exception.AuthenticationException;
import run.halo.app.model.entity.User;
import run.halo.app.security.authentication.Authentication;
import run.halo.app.security.context.SecurityContextHolder;
import run.halo.app.security.support.UserDetail;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.core.MethodParameter; import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
@ -12,6 +7,11 @@ import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer; import org.springframework.web.method.support.ModelAndViewContainer;
import run.halo.app.exception.AuthenticationException;
import run.halo.app.model.entity.User;
import run.halo.app.security.authentication.Authentication;
import run.halo.app.security.context.SecurityContextHolder;
import run.halo.app.security.support.UserDetail;
import java.util.Optional; import java.util.Optional;

View File

@ -1,13 +1,12 @@
package run.halo.app.security.support; package run.halo.app.security.support;
import run.halo.app.exception.AuthenticationException;
import run.halo.app.model.entity.User;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.ToString; import lombok.ToString;
import org.springframework.lang.NonNull; import org.springframework.lang.NonNull;
import run.halo.app.exception.AuthenticationException; import run.halo.app.exception.AuthenticationException;
import run.halo.app.model.entity.User;
/** /**
* User detail. * User detail.

View File

@ -50,6 +50,7 @@ public interface AdminService {
/** /**
* Get system environments * Get system environments
*
* @return environments * @return environments
*/ */
@NonNull @NonNull

View File

@ -59,6 +59,7 @@ public interface AttachmentService extends CrudService<Attachment, Integer> {
/** /**
* List all media type. * List all media type.
*
* @return list of media type * @return list of media type
*/ */
List<String> listAllMediaType(); List<String> listAllMediaType();

View File

@ -1,12 +1,12 @@
package run.halo.app.service; package run.halo.app.service;
import org.springframework.data.domain.Sort;
import org.springframework.lang.NonNull;
import run.halo.app.model.dto.LinkDTO; import run.halo.app.model.dto.LinkDTO;
import run.halo.app.model.entity.Link; import run.halo.app.model.entity.Link;
import run.halo.app.model.params.LinkParam; import run.halo.app.model.params.LinkParam;
import run.halo.app.model.vo.LinkTeamVO; import run.halo.app.model.vo.LinkTeamVO;
import run.halo.app.service.base.CrudService; import run.halo.app.service.base.CrudService;
import org.springframework.data.domain.Sort;
import org.springframework.lang.NonNull;
import java.util.List; import java.util.List;

View File

@ -1,9 +1,9 @@
package run.halo.app.service; package run.halo.app.service;
import org.springframework.data.domain.Page;
import run.halo.app.model.dto.LogDTO; import run.halo.app.model.dto.LogDTO;
import run.halo.app.model.entity.Log; import run.halo.app.model.entity.Log;
import run.halo.app.service.base.CrudService; import run.halo.app.service.base.CrudService;
import org.springframework.data.domain.Page;
/** /**
* Log service. * Log service.

View File

@ -32,11 +32,11 @@ public interface MailService {
/** /**
* Send mail with attachments * Send mail with attachments
* *
* @param to recipient * @param to recipient
* @param subject subject * @param subject subject
* @param content content * @param content content
* @param templateName template name * @param templateName template name
* @param attachFilename attachment path * @param attachFilename attachment path
*/ */
void sendAttachMail(String to, String subject, Map<String, Object> content, String templateName, String attachFilename); void sendAttachMail(String to, String subject, Map<String, Object> content, String templateName, String attachFilename);
} }

View File

@ -48,7 +48,7 @@ public interface PhotoService extends CrudService<Photo, Integer> {
/** /**
* Pages photo output dtos. * Pages photo output dtos.
* *
* @param pageable page info must not be null * @param pageable page info must not be null
* @param photoQuery photoQuery * @param photoQuery photoQuery
* @return a page of photo output dto * @return a page of photo output dto
*/ */

View File

@ -106,6 +106,24 @@ public interface PostService extends BasePostService<Post> {
@NonNull @NonNull
Post importMarkdown(@NonNull String markdown); Post importMarkdown(@NonNull String markdown);
/**
* Export post to markdown file by post id.
*
* @param id post id
* @return markdown file content
*/
@NonNull
String exportMarkdown(@NonNull Integer id);
/**
* Export post to markdown file by post.
*
* @param post current post
* @return markdown file content
*/
@NonNull
String exportMarkdown(@NonNull Post post);
/** /**
* Converts to detail vo. * Converts to detail vo.
* *

View File

@ -1,16 +1,16 @@
package run.halo.app.service; package run.halo.app.service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import run.halo.app.model.dto.TagWithPostCountDTO; import run.halo.app.model.dto.TagWithPostCountDTO;
import run.halo.app.model.entity.Post; import run.halo.app.model.entity.Post;
import run.halo.app.model.entity.PostTag; import run.halo.app.model.entity.PostTag;
import run.halo.app.model.entity.Tag; import run.halo.app.model.entity.Tag;
import run.halo.app.service.base.CrudService; import run.halo.app.service.base.CrudService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;

View File

@ -54,6 +54,24 @@ public interface SheetService extends BasePostService<Sheet> {
@NonNull @NonNull
Sheet importMarkdown(@NonNull String markdown); Sheet importMarkdown(@NonNull String markdown);
/**
* Export sheet to markdown file by sheet id.
*
* @param id sheet id
* @return markdown file content
*/
@NonNull
String exportMarkdown(@NonNull Integer id);
/**
* Export sheet to markdown file by sheet.
*
* @param sheet current sheet
* @return markdown file content
*/
@NonNull
String exportMarkdown(@NonNull Sheet sheet);
/** /**
* Converts to list dto page. * Converts to list dto page.
* *

View File

@ -1,13 +1,13 @@
package run.halo.app.service.base; package run.halo.app.service.base;
import run.halo.app.exception.NotFoundException;
import run.halo.app.repository.base.BaseRepository;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import run.halo.app.exception.NotFoundException;
import run.halo.app.repository.base.BaseRepository;
import java.lang.reflect.ParameterizedType; import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type; import java.lang.reflect.Type;

View File

@ -122,6 +122,7 @@ public interface BasePostService<POST extends BasePost> extends CrudService<POST
/** /**
* Lists latest posts. * Lists latest posts.
*
* @param top top number must not be less than 0 * @param top top number must not be less than 0
* @return latest posts * @return latest posts
*/ */

View File

@ -1,12 +1,12 @@
package run.halo.app.service.base; package run.halo.app.service.base;
import org.springframework.transaction.annotation.Transactional;
import run.halo.app.exception.NotFoundException;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.lang.NonNull; import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.transaction.annotation.Transactional;
import run.halo.app.exception.NotFoundException;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;

View File

@ -192,7 +192,7 @@ public class AdminServiceImpl implements AdminService {
Assert.hasText(refreshToken, "Refresh token must not be blank"); Assert.hasText(refreshToken, "Refresh token must not be blank");
Integer userId = cacheStore.getAny(SecurityUtils.buildTokenRefreshKey(refreshToken), Integer.class) Integer userId = cacheStore.getAny(SecurityUtils.buildTokenRefreshKey(refreshToken), Integer.class)
.orElseThrow(() -> new BadRequestException("The refresh token may have been expired already").setErrorData(refreshToken)); .orElseThrow(() -> new BadRequestException("登陆状态已失效,请重新登陆").setErrorData(refreshToken));
// Get user info // Get user info
User user = userService.getById(userId); User user = userService.getById(userId);

View File

@ -1,5 +1,6 @@
package run.halo.app.service.impl; package run.halo.app.service.impl;
import cn.hutool.core.util.URLUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -55,13 +56,10 @@ import java.util.stream.Collectors;
@Slf4j @Slf4j
public abstract class BaseCommentServiceImpl<COMMENT extends BaseComment> extends AbstractCrudService<COMMENT, Long> implements BaseCommentService<COMMENT> { public abstract class BaseCommentServiceImpl<COMMENT extends BaseComment> extends AbstractCrudService<COMMENT, Long> implements BaseCommentService<COMMENT> {
private final BaseCommentRepository<COMMENT> baseCommentRepository;
protected final OptionService optionService; protected final OptionService optionService;
protected final UserService userService; protected final UserService userService;
protected final ApplicationEventPublisher eventPublisher; protected final ApplicationEventPublisher eventPublisher;
private final BaseCommentRepository<COMMENT> baseCommentRepository;
public BaseCommentServiceImpl(BaseCommentRepository<COMMENT> baseCommentRepository, public BaseCommentServiceImpl(BaseCommentRepository<COMMENT> baseCommentRepository,
OptionService optionService, OptionService optionService,
@ -247,6 +245,10 @@ public abstract class BaseCommentServiceImpl<COMMENT extends BaseComment> extend
comment.setGavatarMd5(DigestUtils.md5Hex(comment.getEmail())); comment.setGavatarMd5(DigestUtils.md5Hex(comment.getEmail()));
} }
if (StringUtils.isNotEmpty(comment.getAuthorUrl())) {
comment.setAuthorUrl(URLUtil.normalize(comment.getAuthorUrl()));
}
if (authentication != null) { if (authentication != null) {
// Comment of blogger // Comment of blogger
comment.setIsAdmin(true); comment.setIsAdmin(true);

View File

@ -1,5 +1,12 @@
package run.halo.app.service.impl; package run.halo.app.service.impl;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Sort;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import run.halo.app.exception.AlreadyExistsException; import run.halo.app.exception.AlreadyExistsException;
import run.halo.app.model.dto.LinkDTO; import run.halo.app.model.dto.LinkDTO;
import run.halo.app.model.entity.Link; import run.halo.app.model.entity.Link;
@ -9,13 +16,6 @@ import run.halo.app.repository.LinkRepository;
import run.halo.app.service.LinkService; import run.halo.app.service.LinkService;
import run.halo.app.service.base.AbstractCrudService; import run.halo.app.service.base.AbstractCrudService;
import run.halo.app.utils.ServiceUtils; import run.halo.app.utils.ServiceUtils;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Sort;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -107,7 +107,7 @@ public class LinkServiceImpl extends AbstractCrudService<Link, Integer> implemen
return Collections.emptyList(); return Collections.emptyList();
} }
return links.stream().map(link -> new LinkDTO().<LinkDTO>convertFrom(link)) return links.stream().map(link -> (LinkDTO) new LinkDTO().convertFrom(link))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
} }

View File

@ -1,15 +1,15 @@
package run.halo.app.service.impl; package run.halo.app.service.impl;
import run.halo.app.model.dto.LogDTO;
import run.halo.app.model.entity.Log;
import run.halo.app.repository.LogRepository;
import run.halo.app.service.LogService;
import run.halo.app.service.base.AbstractCrudService;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import run.halo.app.model.dto.LogDTO;
import run.halo.app.model.entity.Log;
import run.halo.app.repository.LogRepository;
import run.halo.app.service.LogService;
import run.halo.app.service.base.AbstractCrudService;
/** /**
* LogService implementation class * LogService implementation class

View File

@ -153,7 +153,7 @@ public class MenuServiceImpl extends AbstractCrudService<Menu, Integer> implemen
} }
return menus.stream() return menus.stream()
.map(menu -> new MenuDTO().<MenuDTO>convertFrom(menu)) .map(menu -> (MenuDTO) new MenuDTO().convertFrom(menu))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }

View File

@ -6,7 +6,6 @@ import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import run.halo.app.model.dto.CategoryDTO;
import run.halo.app.model.dto.CategoryWithPostCountDTO; import run.halo.app.model.dto.CategoryWithPostCountDTO;
import run.halo.app.model.entity.Category; import run.halo.app.model.entity.Category;
import run.halo.app.model.entity.Post; import run.halo.app.model.entity.Post;

View File

@ -1,5 +1,6 @@
package run.halo.app.service.impl; package run.halo.app.service.impl;
import cn.hutool.core.text.StrBuilder;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;
@ -147,7 +148,7 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
@Override @Override
public PostDetailVO createBy(Post postToCreate, Set<Integer> tagIds, Set<Integer> categoryIds, boolean autoSave) { public PostDetailVO createBy(Post postToCreate, Set<Integer> tagIds, Set<Integer> categoryIds, boolean autoSave) {
PostDetailVO createdPost = createOrUpdate(postToCreate, tagIds, categoryIds); PostDetailVO createdPost = createOrUpdate(postToCreate, tagIds, categoryIds);
if(!autoSave){ if (!autoSave) {
// Log the creation // Log the creation
LogEvent logEvent = new LogEvent(this, createdPost.getId().toString(), LogType.POST_PUBLISHED, createdPost.getTitle()); LogEvent logEvent = new LogEvent(this, createdPost.getId().toString(), LogType.POST_PUBLISHED, createdPost.getTitle());
eventPublisher.publishEvent(logEvent); eventPublisher.publishEvent(logEvent);
@ -160,7 +161,7 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
// Set edit time // Set edit time
postToUpdate.setEditTime(DateUtils.now()); postToUpdate.setEditTime(DateUtils.now());
PostDetailVO updatedPost = createOrUpdate(postToUpdate, tagIds, categoryIds); PostDetailVO updatedPost = createOrUpdate(postToUpdate, tagIds, categoryIds);
if(!autoSave){ if (!autoSave) {
// Log the creation // Log the creation
LogEvent logEvent = new LogEvent(this, updatedPost.getId().toString(), LogType.POST_EDITED, updatedPost.getTitle()); LogEvent logEvent = new LogEvent(this, updatedPost.getId().toString(), LogType.POST_EDITED, updatedPost.getTitle());
eventPublisher.publishEvent(logEvent); eventPublisher.publishEvent(logEvent);
@ -286,6 +287,51 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
return null; return null;
} }
@Override
public String exportMarkdown(Integer id) {
Assert.notNull(id, "Post id must not be null");
Post post = getById(id);
return exportMarkdown(post);
}
@Override
public String exportMarkdown(Post post) {
Assert.notNull(post, "Post must not be null");
StrBuilder content = new StrBuilder("---\n");
content.append("type: ").append("post").append("\n");
content.append("title: ").append(post.getTitle()).append("\n");
content.append("permalink: ").append(post.getUrl()).append("\n");
content.append("thumbnail: ").append(post.getThumbnail()).append("\n");
content.append("status: ").append(post.getStatus()).append("\n");
content.append("date: ").append(post.getCreateTime()).append("\n");
content.append("updated: ").append(post.getEditTime()).append("\n");
content.append("comments: ").append(!post.getDisallowComment()).append("\n");
List<Tag> tags = postTagService.listTagsBy(post.getId());
if (tags.size() > 0) {
content.append("tags:").append("\n");
for (Tag tag : tags) {
content.append(" - ").append(tag.getName()).append("\n");
}
}
List<Category> categories = postCategoryService.listCategoryBy(post.getId());
if (categories.size() > 0) {
content.append("categories:").append("\n");
for (Category category : categories) {
content.append(" - ").append(category.getName()).append("\n");
}
}
content.append("---\n\n");
content.append(post.getOriginalContent());
return content.toString();
}
@Override @Override
public PostDetailVO convertToDetailVo(Post post) { public PostDetailVO convertToDetailVo(Post post) {
return convertTo(post, return convertTo(post,
@ -349,7 +395,7 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
.orElseGet(LinkedList::new) .orElseGet(LinkedList::new)
.stream() .stream()
.filter(Objects::nonNull) .filter(Objects::nonNull)
.map(tag -> new TagDTO().<TagDTO>convertFrom(tag)) .map(tag -> (TagDTO) new TagDTO().convertFrom(tag))
.collect(Collectors.toList())); .collect(Collectors.toList()));
// Set categories // Set categories
@ -357,7 +403,7 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
.orElseGet(LinkedList::new) .orElseGet(LinkedList::new)
.stream() .stream()
.filter(Objects::nonNull) .filter(Objects::nonNull)
.map(category -> new CategoryDTO().<CategoryDTO>convertFrom(category)) .map(category -> (CategoryDTO) new CategoryDTO().convertFrom(category))
.collect(Collectors.toList())); .collect(Collectors.toList()));
// Set comment count // Set comment count

View File

@ -1,5 +1,11 @@
package run.halo.app.service.impl; package run.halo.app.service.impl;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import run.halo.app.model.dto.TagWithPostCountDTO; import run.halo.app.model.dto.TagWithPostCountDTO;
import run.halo.app.model.entity.Post; import run.halo.app.model.entity.Post;
import run.halo.app.model.entity.PostTag; import run.halo.app.model.entity.PostTag;
@ -11,12 +17,6 @@ import run.halo.app.repository.TagRepository;
import run.halo.app.service.PostTagService; import run.halo.app.service.PostTagService;
import run.halo.app.service.base.AbstractCrudService; import run.halo.app.service.base.AbstractCrudService;
import run.halo.app.utils.ServiceUtils; import run.halo.app.utils.ServiceUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;

View File

@ -1,5 +1,6 @@
package run.halo.app.service.impl; package run.halo.app.service.impl;
import cn.hutool.core.text.StrBuilder;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
@ -108,6 +109,33 @@ public class SheetServiceImpl extends BasePostServiceImpl<Sheet> implements Shee
return null; return null;
} }
@Override
public String exportMarkdown(Integer id) {
Assert.notNull(id, "sheet id must not be null");
Sheet sheet = getById(id);
return exportMarkdown(sheet);
}
@Override
public String exportMarkdown(Sheet sheet) {
Assert.notNull(sheet, "Sheet must not be null");
StrBuilder content = new StrBuilder("---\n");
content.append("type: ").append("sheet").append("\n");
content.append("title: ").append(sheet.getTitle()).append("\n");
content.append("permalink: ").append(sheet.getUrl()).append("\n");
content.append("thumbnail: ").append(sheet.getThumbnail()).append("\n");
content.append("status: ").append(sheet.getStatus()).append("\n");
content.append("date: ").append(sheet.getCreateTime()).append("\n");
content.append("updated: ").append(sheet.getEditTime()).append("\n");
content.append("comments: ").append(!sheet.getDisallowComment()).append("\n");
content.append("---\n\n");
content.append(sheet.getOriginalContent());
return content.toString();
}
@Override @Override
public Sheet removeById(Integer id) { public Sheet removeById(Integer id) {
Sheet sheet = super.removeById(id); Sheet sheet = super.removeById(id);

View File

@ -1,7 +1,6 @@
package run.halo.app.service.support; package run.halo.app.service.support;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import java.nio.charset.Charset; import java.nio.charset.Charset;

View File

@ -1,6 +1,5 @@
package run.halo.app.utils; package run.halo.app.utils;
import run.halo.app.exception.BeanUtilsException;
import org.springframework.beans.BeanWrapperImpl; import org.springframework.beans.BeanWrapperImpl;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.lang.NonNull; import org.springframework.lang.NonNull;

Some files were not shown because too many files have changed in this diff Show More