From a70780c5df62b5da93a329dfa5c8bd41124e3020 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Wed, 18 Mar 2020 21:44:46 +0800 Subject: [PATCH] style: code. (#692) --- ...ore.java => AbstractStringCacheStore.java} | 2 +- .../halo/app/cache/InMemoryCacheStore.java | 2 +- .../run/halo/app/cache/LevelCacheStore.java | 6 +- .../app/cache/lock/CacheLockInterceptor.java | 6 +- .../halo/app/config/HaloConfiguration.java | 6 +- .../admin/api/BackupController.java | 4 +- .../admin/api/DataProcessController.java | 78 ++++---- .../admin/api/InstallController.java | 17 +- .../controller/admin/api/PostController.java | 6 +- .../controller/admin/api/SheetController.java | 6 +- .../admin/api/StaticPageController.java | 184 +++++++++--------- .../controller/admin/api/TraceController.java | 34 ---- .../content/ContentContentController.java | 11 +- .../controller/content/model/PostModel.java | 6 +- .../controller/content/model/SheetModel.java | 6 +- .../app/controller/core/CommonController.java | 6 +- .../app/core/ControllerExceptionHandler.java | 6 +- .../tag/PaginationTagDirective.java | 52 ++--- ...ent.java => AbstractCommentBaseEvent.java} | 4 +- .../app/event/comment/CommentNewEvent.java | 2 +- .../app/event/comment/CommentReplyEvent.java | 2 +- ...eption.java => AbstractHaloException.java} | 15 +- .../exception/AuthenticationException.java | 2 +- .../app/exception/BadRequestException.java | 2 +- .../app/exception/BeanUtilsException.java | 2 +- .../app/exception/ForbiddenException.java | 2 +- .../halo/app/exception/NotFoundException.java | 2 +- .../halo/app/exception/ServiceException.java | 2 +- .../app/handler/file/AliOssFileHandler.java | 8 +- .../app/handler/file/QiniuOssFileHandler.java | 63 +++--- .../handler/file/TencentCosFileHandler.java | 8 +- .../comment/CommentEventListener.java | 8 +- .../listener/theme/ThemeUpdatedListener.java | 6 +- .../app/model/dto/post/BasePostSimpleDTO.java | 6 +- .../run/halo/app/model/enums/InputType.java | 21 ++ .../run/halo/app/model/enums/LogType.java | 47 +++++ .../java/run/halo/app/model/enums/Mode.java | 16 ++ .../model/properties/AliOssProperties.java | 4 +- .../model/properties/BaiduBosProperties.java | 4 +- .../app/model/properties/EmailProperties.java | 21 ++ .../model/properties/QiniuOssProperties.java | 4 +- .../properties/TencentCosProperties.java | 4 +- .../app/model/properties/UpOssProperties.java | 4 +- .../run/halo/app/model/support/BackupDto.java | 43 ---- .../run/halo/app/model/support/HaloConst.java | 6 + .../halo/app/model/support/QiNiuPutSet.java | 40 ---- .../filter/AbstractAuthenticationFilter.java | 10 +- .../filter/AdminAuthenticationFilter.java | 4 +- .../filter/ApiAuthenticationFilter.java | 4 +- .../app/security/filter/ContentFilter.java | 4 +- .../handler/AuthenticationFailureHandler.java | 4 +- .../ContentAuthenticationFailureHandler.java | 4 +- .../DefaultAuthenticationFailureHandler.java | 4 +- .../service/impl/OneTimeTokenServiceImpl.java | 6 +- .../run/halo/app/service/OptionService.java | 10 + .../app/service/impl/AdminServiceImpl.java | 6 +- .../app/service/impl/CategoryServiceImpl.java | 10 +- .../app/service/impl/OptionServiceImpl.java | 49 +++-- .../service/impl/PostCategoryServiceImpl.java | 6 +- .../service/impl/PostCommentServiceImpl.java | 16 +- .../app/service/impl/PostServiceImpl.java | 23 ++- .../app/service/impl/PostTagServiceImpl.java | 6 +- .../service/impl/SheetCommentServiceImpl.java | 6 +- .../app/service/impl/SheetServiceImpl.java | 9 +- .../halo/app/service/impl/TagServiceImpl.java | 6 +- .../app/service/impl/ThemeServiceImpl.java | 6 +- .../app/service/impl/UserServiceImpl.java | 6 +- .../java/run/halo/app/utils/HaloUtils.java | 3 +- .../java/run/halo/app/utils/SlugUtils.java | 4 +- .../run/halo/app/cache/CacheStoreTest.java | 2 +- .../service/impl/OptionServiceImplTest.java | 4 +- 71 files changed, 535 insertions(+), 463 deletions(-) rename src/main/java/run/halo/app/cache/{StringCacheStore.java => AbstractStringCacheStore.java} (94%) delete mode 100644 src/main/java/run/halo/app/controller/admin/api/TraceController.java rename src/main/java/run/halo/app/event/comment/{CommentBaseEvent.java => AbstractCommentBaseEvent.java} (82%) rename src/main/java/run/halo/app/exception/{HaloException.java => AbstractHaloException.java} (65%) delete mode 100644 src/main/java/run/halo/app/model/support/BackupDto.java delete mode 100644 src/main/java/run/halo/app/model/support/QiNiuPutSet.java diff --git a/src/main/java/run/halo/app/cache/StringCacheStore.java b/src/main/java/run/halo/app/cache/AbstractStringCacheStore.java similarity index 94% rename from src/main/java/run/halo/app/cache/StringCacheStore.java rename to src/main/java/run/halo/app/cache/AbstractStringCacheStore.java index f683ceb29..bc20c13ea 100644 --- a/src/main/java/run/halo/app/cache/StringCacheStore.java +++ b/src/main/java/run/halo/app/cache/AbstractStringCacheStore.java @@ -17,7 +17,7 @@ import java.util.concurrent.TimeUnit; * @author johnniang */ @Slf4j -public abstract class StringCacheStore extends AbstractCacheStore { +public abstract class AbstractStringCacheStore extends AbstractCacheStore { public void putAny(String key, T value) { try { diff --git a/src/main/java/run/halo/app/cache/InMemoryCacheStore.java b/src/main/java/run/halo/app/cache/InMemoryCacheStore.java index f358ee461..bc647c778 100644 --- a/src/main/java/run/halo/app/cache/InMemoryCacheStore.java +++ b/src/main/java/run/halo/app/cache/InMemoryCacheStore.java @@ -17,7 +17,7 @@ import java.util.concurrent.locks.ReentrantLock; * @author johnniang */ @Slf4j -public class InMemoryCacheStore extends StringCacheStore { +public class InMemoryCacheStore extends AbstractStringCacheStore { /** * Cleaner schedule period. (ms) diff --git a/src/main/java/run/halo/app/cache/LevelCacheStore.java b/src/main/java/run/halo/app/cache/LevelCacheStore.java index 1c57f20c1..4306a3a2a 100644 --- a/src/main/java/run/halo/app/cache/LevelCacheStore.java +++ b/src/main/java/run/halo/app/cache/LevelCacheStore.java @@ -22,7 +22,7 @@ import java.util.*; * Create by Pencilso on 2020/1/9 7:20 下午 */ @Slf4j -public class LevelCacheStore extends StringCacheStore { +public class LevelCacheStore extends AbstractStringCacheStore { /** * Cleaner schedule period. (ms) */ @@ -37,7 +37,9 @@ public class LevelCacheStore extends StringCacheStore { @PostConstruct public void init() { - if (LEVEL_DB != null) return; + if (LEVEL_DB != null) { + return; + } try { //work path File folder = new File(haloProperties.getWorkDir() + ".leveldb"); diff --git a/src/main/java/run/halo/app/cache/lock/CacheLockInterceptor.java b/src/main/java/run/halo/app/cache/lock/CacheLockInterceptor.java index 81927ea96..347cd1e3b 100644 --- a/src/main/java/run/halo/app/cache/lock/CacheLockInterceptor.java +++ b/src/main/java/run/halo/app/cache/lock/CacheLockInterceptor.java @@ -9,7 +9,7 @@ import org.aspectj.lang.reflect.MethodSignature; import org.springframework.context.annotation.Configuration; import org.springframework.lang.NonNull; import org.springframework.util.Assert; -import run.halo.app.cache.StringCacheStore; +import run.halo.app.cache.AbstractStringCacheStore; import run.halo.app.exception.FrequentAccessException; import run.halo.app.exception.ServiceException; import run.halo.app.utils.ServletUtils; @@ -31,9 +31,9 @@ public class CacheLockInterceptor { private final static String CACHE_LOCK_VALUE = "locked"; - private final StringCacheStore cacheStore; + private final AbstractStringCacheStore cacheStore; - public CacheLockInterceptor(StringCacheStore cacheStore) { + public CacheLockInterceptor(AbstractStringCacheStore cacheStore) { this.cacheStore = cacheStore; } diff --git a/src/main/java/run/halo/app/config/HaloConfiguration.java b/src/main/java/run/halo/app/config/HaloConfiguration.java index 390de3685..26e38374a 100644 --- a/src/main/java/run/halo/app/config/HaloConfiguration.java +++ b/src/main/java/run/halo/app/config/HaloConfiguration.java @@ -11,9 +11,9 @@ import org.springframework.context.annotation.Configuration; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.web.client.RestTemplate; +import run.halo.app.cache.AbstractStringCacheStore; import run.halo.app.cache.InMemoryCacheStore; import run.halo.app.cache.LevelCacheStore; -import run.halo.app.cache.StringCacheStore; import run.halo.app.config.properties.HaloProperties; import run.halo.app.utils.HttpClientUtils; @@ -51,8 +51,8 @@ public class HaloConfiguration { @Bean @ConditionalOnMissingBean - public StringCacheStore stringCacheStore() { - StringCacheStore stringCacheStore; + public AbstractStringCacheStore stringCacheStore() { + AbstractStringCacheStore stringCacheStore; switch (haloProperties.getCache()) { case "level": stringCacheStore = new LevelCacheStore(); diff --git a/src/main/java/run/halo/app/controller/admin/api/BackupController.java b/src/main/java/run/halo/app/controller/admin/api/BackupController.java index 2c4d64ae2..3fb8ca8bf 100644 --- a/src/main/java/run/halo/app/controller/admin/api/BackupController.java +++ b/src/main/java/run/halo/app/controller/admin/api/BackupController.java @@ -62,7 +62,7 @@ public class BackupController { // Load file as resource Resource backupResource = backupService.loadFileAsResource(haloProperties.getBackupDir(), fileName); - String contentType = "application/octet-stream"; + String contentType = MediaType.APPLICATION_OCTET_STREAM_VALUE; // Try to determine file's content type try { contentType = request.getServletContext().getMimeType(backupResource.getFile().getAbsolutePath()); @@ -119,7 +119,7 @@ public class BackupController { // Load exported data as resource Resource exportDataResource = backupService.loadFileAsResource(haloProperties.getDataExportDir(), fileName); - String contentType = "application/octet-stream"; + String contentType = MediaType.APPLICATION_OCTET_STREAM_VALUE; // Try to determine file's content type try { contentType = request.getServletContext().getMimeType(exportDataResource.getFile().getAbsolutePath()); diff --git a/src/main/java/run/halo/app/controller/admin/api/DataProcessController.java b/src/main/java/run/halo/app/controller/admin/api/DataProcessController.java index adeac68c7..2e6ec122a 100644 --- a/src/main/java/run/halo/app/controller/admin/api/DataProcessController.java +++ b/src/main/java/run/halo/app/controller/admin/api/DataProcessController.java @@ -1,30 +1,28 @@ -package run.halo.app.controller.admin.api; - -import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import run.halo.app.service.DataProcessService; -import run.halo.app.service.ThemeSettingService; - -/** - * @author ryanwang - * @date 2019-12-29 - */ -@RestController -@RequestMapping("/api/admin/data/process") -public class DataProcessController { - - private final DataProcessService dataProcessService; - - private final ThemeSettingService themeSettingService; - - public DataProcessController(DataProcessService dataProcessService, - ThemeSettingService themeSettingService) { - this.dataProcessService = dataProcessService; - this.themeSettingService = themeSettingService; - } - +//package run.halo.app.controller.admin.api; +// +//import io.swagger.annotations.ApiOperation; +//import org.springframework.web.bind.annotation.*; +//import run.halo.app.service.DataProcessService; +//import run.halo.app.service.ThemeSettingService; +// +///** +// * @author ryanwang +// * @date 2019-12-29 +// */ +//@RestController +//@RequestMapping("/api/admin/data/process") +//public class DataProcessController { +// +// private final DataProcessService dataProcessService; +// +// private final ThemeSettingService themeSettingService; +// +// public DataProcessController(DataProcessService dataProcessService, +// ThemeSettingService themeSettingService) { +// this.dataProcessService = dataProcessService; +// this.themeSettingService = themeSettingService; +// } +// // @PutMapping("url/replace") // @ApiOperation("Replace url in all table.") // public void replaceUrl(@RequestParam("oldUrl") String oldUrl, @@ -37,16 +35,16 @@ public class DataProcessController { // public void deleteInactivatedThemeSettings() { // themeSettingService.deleteInactivated(); // } - - @DeleteMapping("tags/unused") - @ApiOperation("Delete unused tags") - public void deleteUnusedTags() { - // TODO - } - - @DeleteMapping("categories/unused") - @ApiOperation("Delete unused categories") - public void deleteUnusedCategories() { - // TODO - } -} +// +// @DeleteMapping("tags/unused") +// @ApiOperation("Delete unused tags") +// public void deleteUnusedTags() { +// // TODO +// } +// +// @DeleteMapping("categories/unused") +// @ApiOperation("Delete unused categories") +// public void deleteUnusedCategories() { +// // TODO +// } +//} diff --git a/src/main/java/run/halo/app/controller/admin/api/InstallController.java b/src/main/java/run/halo/app/controller/admin/api/InstallController.java index 84ef913cc..6430dd6bf 100644 --- a/src/main/java/run/halo/app/controller/admin/api/InstallController.java +++ b/src/main/java/run/halo/app/controller/admin/api/InstallController.java @@ -1,6 +1,5 @@ package run.halo.app.controller.admin.api; -import cn.hutool.core.text.StrBuilder; import cn.hutool.crypto.SecureUtil; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; @@ -15,7 +14,6 @@ import org.springframework.web.bind.annotation.ResponseBody; import run.halo.app.cache.lock.CacheLock; import run.halo.app.event.logger.LogEvent; import run.halo.app.exception.BadRequestException; -import run.halo.app.model.entity.BaseComment; import run.halo.app.model.entity.Category; import run.halo.app.model.entity.PostComment; import run.halo.app.model.entity.User; @@ -159,15 +157,15 @@ public class InstallController { @Nullable - private BaseComment createDefaultComment(@Nullable PostDetailVO post) { + private void createDefaultComment(@Nullable PostDetailVO post) { if (post == null) { - return null; + return; } long commentCount = postCommentService.count(); if (commentCount > 0) { - return null; + return; } PostComment comment = new PostComment(); @@ -176,7 +174,7 @@ public class InstallController { comment.setContent("欢迎使用 Halo,这是你的第一条评论,头像来自 [Gravatar](https://cn.gravatar.com),你也可以通过注册 [Gravatar](https://cn.gravatar.com) 来显示自己的头像。"); comment.setEmail("hi@halo.run"); comment.setPostId(post.getId()); - return postCommentService.create(comment); + postCommentService.create(comment); } @Nullable @@ -260,10 +258,9 @@ public class InstallController { // Update user return userService.update(user); }).orElseGet(() -> { - StrBuilder gravatar = new StrBuilder("//cn.gravatar.com/avatar/"); - gravatar.append(SecureUtil.md5(installParam.getEmail())); - gravatar.append("?s=256&d=mm"); - installParam.setAvatar(gravatar.toString()); + String gravatar = "//cn.gravatar.com/avatar/" + SecureUtil.md5(installParam.getEmail()) + + "?s=256&d=mm"; + installParam.setAvatar(gravatar); return userService.createBy(installParam); }); } diff --git a/src/main/java/run/halo/app/controller/admin/api/PostController.java b/src/main/java/run/halo/app/controller/admin/api/PostController.java index 94d0296e2..fba3920cc 100644 --- a/src/main/java/run/halo/app/controller/admin/api/PostController.java +++ b/src/main/java/run/halo/app/controller/admin/api/PostController.java @@ -6,7 +6,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableDefault; import org.springframework.web.bind.annotation.*; -import run.halo.app.cache.StringCacheStore; +import run.halo.app.cache.AbstractStringCacheStore; import run.halo.app.model.dto.post.BasePostDetailDTO; import run.halo.app.model.dto.post.BasePostMinimalDTO; import run.halo.app.model.dto.post.BasePostSimpleDTO; @@ -43,12 +43,12 @@ public class PostController { private final PostService postService; - private final StringCacheStore cacheStore; + private final AbstractStringCacheStore cacheStore; private final OptionService optionService; public PostController(PostService postService, - StringCacheStore cacheStore, + AbstractStringCacheStore cacheStore, OptionService optionService) { this.postService = postService; this.cacheStore = cacheStore; diff --git a/src/main/java/run/halo/app/controller/admin/api/SheetController.java b/src/main/java/run/halo/app/controller/admin/api/SheetController.java index 2a41b7b5b..d862e293e 100644 --- a/src/main/java/run/halo/app/controller/admin/api/SheetController.java +++ b/src/main/java/run/halo/app/controller/admin/api/SheetController.java @@ -6,7 +6,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableDefault; import org.springframework.web.bind.annotation.*; -import run.halo.app.cache.StringCacheStore; +import run.halo.app.cache.AbstractStringCacheStore; import run.halo.app.model.dto.InternalSheetDTO; import run.halo.app.model.dto.post.BasePostDetailDTO; import run.halo.app.model.dto.post.BasePostMinimalDTO; @@ -41,12 +41,12 @@ public class SheetController { private final SheetService sheetService; - private final StringCacheStore cacheStore; + private final AbstractStringCacheStore cacheStore; private final OptionService optionService; public SheetController(SheetService sheetService, - StringCacheStore cacheStore, + AbstractStringCacheStore cacheStore, OptionService optionService) { this.sheetService = sheetService; this.cacheStore = cacheStore; diff --git a/src/main/java/run/halo/app/controller/admin/api/StaticPageController.java b/src/main/java/run/halo/app/controller/admin/api/StaticPageController.java index 2a0b95a6f..28c762e07 100644 --- a/src/main/java/run/halo/app/controller/admin/api/StaticPageController.java +++ b/src/main/java/run/halo/app/controller/admin/api/StaticPageController.java @@ -1,92 +1,92 @@ -package run.halo.app.controller.admin.api; - -import cn.hutool.core.io.FileUtil; -import io.swagger.annotations.ApiOperation; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.client.RestTemplate; -import run.halo.app.model.properties.NetlifyStaticDeployProperties; -import run.halo.app.model.support.StaticPageFile; -import run.halo.app.service.OptionService; -import run.halo.app.service.StaticPageService; - -import java.io.FileNotFoundException; -import java.nio.file.Path; -import java.util.Collections; -import java.util.List; - -/** - * Static page controller. - * - * @author ryanwang - * @date 2019-12-25 - */ -@RestController -@RequestMapping("/api/admin/static_page") -public class StaticPageController { - - private final static String DEPLOY_API = "https://api.netlify.com/api/v1/sites/%s/deploys"; - - private final OptionService optionService; - - private final RestTemplate httpsRestTemplate; - - private final StaticPageService staticPageService; - - public StaticPageController(StaticPageService staticPageService, - OptionService optionService, - RestTemplate httpsRestTemplate) { - this.staticPageService = staticPageService; - this.optionService = optionService; - this.httpsRestTemplate = httpsRestTemplate; - - MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter(); - mappingJackson2HttpMessageConverter.setSupportedMediaTypes(Collections.singletonList(MediaType.ALL)); - this.httpsRestTemplate.getMessageConverters().add(mappingJackson2HttpMessageConverter); - } - - @GetMapping - @ApiOperation("List static page files.") - public List list() { - return staticPageService.listFile(); - } - - @GetMapping("generate") - @ApiOperation("Generate static page files.") - public void generate() { - staticPageService.generate(); - } - - @PostMapping("deploy") - @ApiOperation("Deploy static page to remove platform") - public void deploy() { - staticPageService.deploy(); - } - - @GetMapping("netlify") - public void testNetlify() throws FileNotFoundException { - String domain = optionService.getByPropertyOfNonNull(NetlifyStaticDeployProperties.NETLIFY_DOMAIN).toString(); - String siteId = optionService.getByPropertyOfNonNull(NetlifyStaticDeployProperties.NETLIFY_SITE_ID).toString(); - String token = optionService.getByPropertyOfNonNull(NetlifyStaticDeployProperties.NETLIFY_TOKEN).toString(); - - HttpHeaders headers = new HttpHeaders(); - - headers.set("Content-Type", "application/zip"); - headers.set(HttpHeaders.AUTHORIZATION, "Bearer " + token); - - Path path = staticPageService.zipStaticPagesDirectory(); - - byte[] bytes = FileUtil.readBytes(path.toFile()); - - HttpEntity httpEntity = new HttpEntity<>(bytes, headers); - - ResponseEntity responseEntity = httpsRestTemplate.postForEntity(String.format(DEPLOY_API, siteId), httpEntity, Object.class); - } -} +//package run.halo.app.controller.admin.api; +// +//import cn.hutool.core.io.FileUtil; +//import io.swagger.annotations.ApiOperation; +//import org.springframework.http.HttpEntity; +//import org.springframework.http.HttpHeaders; +//import org.springframework.http.MediaType; +//import org.springframework.http.ResponseEntity; +//import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +//import org.springframework.web.bind.annotation.GetMapping; +//import org.springframework.web.bind.annotation.PostMapping; +//import org.springframework.web.bind.annotation.RequestMapping; +//import org.springframework.web.bind.annotation.RestController; +//import org.springframework.web.client.RestTemplate; +//import run.halo.app.model.properties.NetlifyStaticDeployProperties; +//import run.halo.app.model.support.StaticPageFile; +//import run.halo.app.service.OptionService; +//import run.halo.app.service.StaticPageService; +// +//import java.io.FileNotFoundException; +//import java.nio.file.Path; +//import java.util.Collections; +//import java.util.List; +// +///** +// * Static page controller. +// * +// * @author ryanwang +// * @date 2019-12-25 +// */ +//@RestController +//@RequestMapping("/api/admin/static_page") +//public class StaticPageController { +// +// private final static String DEPLOY_API = "https://api.netlify.com/api/v1/sites/%s/deploys"; +// +// private final OptionService optionService; +// +// private final RestTemplate httpsRestTemplate; +// +// private final StaticPageService staticPageService; +// +// public StaticPageController(StaticPageService staticPageService, +// OptionService optionService, +// RestTemplate httpsRestTemplate) { +// this.staticPageService = staticPageService; +// this.optionService = optionService; +// this.httpsRestTemplate = httpsRestTemplate; +// +// MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter(); +// mappingJackson2HttpMessageConverter.setSupportedMediaTypes(Collections.singletonList(MediaType.ALL)); +// this.httpsRestTemplate.getMessageConverters().add(mappingJackson2HttpMessageConverter); +// } +// +// @GetMapping +// @ApiOperation("List static page files.") +// public List list() { +// return staticPageService.listFile(); +// } +// +// @GetMapping("generate") +// @ApiOperation("Generate static page files.") +// public void generate() { +// staticPageService.generate(); +// } +// +// @PostMapping("deploy") +// @ApiOperation("Deploy static page to remove platform") +// public void deploy() { +// staticPageService.deploy(); +// } +// +// @GetMapping("netlify") +// public void testNetlify() throws FileNotFoundException { +// String domain = optionService.getByPropertyOfNonNull(NetlifyStaticDeployProperties.NETLIFY_DOMAIN).toString(); +// String siteId = optionService.getByPropertyOfNonNull(NetlifyStaticDeployProperties.NETLIFY_SITE_ID).toString(); +// String token = optionService.getByPropertyOfNonNull(NetlifyStaticDeployProperties.NETLIFY_TOKEN).toString(); +// +// HttpHeaders headers = new HttpHeaders(); +// +// headers.set("Content-Type", "application/zip"); +// headers.set(HttpHeaders.AUTHORIZATION, "Bearer " + token); +// +// Path path = staticPageService.zipStaticPagesDirectory(); +// +// byte[] bytes = FileUtil.readBytes(path.toFile()); +// +// HttpEntity httpEntity = new HttpEntity<>(bytes, headers); +// +// ResponseEntity responseEntity = httpsRestTemplate.postForEntity(String.format(DEPLOY_API, siteId), httpEntity, Object.class); +// } +//} diff --git a/src/main/java/run/halo/app/controller/admin/api/TraceController.java b/src/main/java/run/halo/app/controller/admin/api/TraceController.java deleted file mode 100644 index f2fed933e..000000000 --- a/src/main/java/run/halo/app/controller/admin/api/TraceController.java +++ /dev/null @@ -1,34 +0,0 @@ -//package run.halo.app.controller.admin.api; -// -//import io.swagger.annotations.ApiOperation; -//import org.springframework.boot.actuate.trace.http.HttpTrace; -//import org.springframework.web.bind.annotation.GetMapping; -//import org.springframework.web.bind.annotation.RequestMapping; -//import org.springframework.web.bind.annotation.RestController; -//import run.halo.app.service.TraceService; -// -//import java.util.List; -// -///** -// * Trace controller. -// * -// * @author johnniang -// * @date 19-6-18 -// */ -//@RestController -//@RequestMapping("/api/admin/traces") -//public class TraceController { -// -// private final TraceService traceService; -// -// public TraceController(TraceService traceService) { -// this.traceService = traceService; -// } -// -// @GetMapping -// @ApiOperation("Lists http traces") -// public List listHttpTraces() { -// return traceService.listHttpTraces(); -// } -// -//} diff --git a/src/main/java/run/halo/app/controller/content/ContentContentController.java b/src/main/java/run/halo/app/controller/content/ContentContentController.java index 1581fb51f..57cd61824 100644 --- a/src/main/java/run/halo/app/controller/content/ContentContentController.java +++ b/src/main/java/run/halo/app/controller/content/ContentContentController.java @@ -5,7 +5,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; -import run.halo.app.cache.StringCacheStore; +import run.halo.app.cache.AbstractStringCacheStore; import run.halo.app.cache.lock.CacheLock; import run.halo.app.controller.content.model.*; import run.halo.app.exception.NotFoundException; @@ -17,7 +17,6 @@ import run.halo.app.model.enums.PostStatus; import run.halo.app.service.OptionService; import run.halo.app.service.PostService; import run.halo.app.service.SheetService; -import run.halo.app.service.ThemeService; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; @@ -53,9 +52,7 @@ public class ContentContentController { private final SheetService sheetService; - private final ThemeService themeService; - - private final StringCacheStore cacheStore; + private final AbstractStringCacheStore cacheStore; public ContentContentController(PostModel postModel, SheetModel sheetModel, @@ -67,8 +64,7 @@ public class ContentContentController { OptionService optionService, PostService postService, SheetService sheetService, - ThemeService themeService, - StringCacheStore cacheStore) { + AbstractStringCacheStore cacheStore) { this.postModel = postModel; this.sheetModel = sheetModel; this.categoryModel = categoryModel; @@ -79,7 +75,6 @@ public class ContentContentController { this.optionService = optionService; this.postService = postService; this.sheetService = sheetService; - this.themeService = themeService; this.cacheStore = cacheStore; } diff --git a/src/main/java/run/halo/app/controller/content/model/PostModel.java b/src/main/java/run/halo/app/controller/content/model/PostModel.java index 676678282..ef525fd25 100644 --- a/src/main/java/run/halo/app/controller/content/model/PostModel.java +++ b/src/main/java/run/halo/app/controller/content/model/PostModel.java @@ -7,7 +7,7 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.stereotype.Component; import org.springframework.ui.Model; -import run.halo.app.cache.StringCacheStore; +import run.halo.app.cache.AbstractStringCacheStore; import run.halo.app.exception.ForbiddenException; import run.halo.app.model.entity.Category; import run.halo.app.model.entity.Post; @@ -50,7 +50,7 @@ public class PostModel { private final OptionService optionService; - private final StringCacheStore cacheStore; + private final AbstractStringCacheStore cacheStore; public PostModel(PostService postService, ThemeService themeService, @@ -60,7 +60,7 @@ public class PostModel { PostTagService postTagService, TagService tagService, OptionService optionService, - StringCacheStore cacheStore) { + AbstractStringCacheStore cacheStore) { this.postService = postService; this.themeService = themeService; this.postCategoryService = postCategoryService; diff --git a/src/main/java/run/halo/app/controller/content/model/SheetModel.java b/src/main/java/run/halo/app/controller/content/model/SheetModel.java index 9d119863a..73d45f311 100644 --- a/src/main/java/run/halo/app/controller/content/model/SheetModel.java +++ b/src/main/java/run/halo/app/controller/content/model/SheetModel.java @@ -3,7 +3,7 @@ package run.halo.app.controller.content.model; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; import org.springframework.ui.Model; -import run.halo.app.cache.StringCacheStore; +import run.halo.app.cache.AbstractStringCacheStore; import run.halo.app.exception.ForbiddenException; import run.halo.app.model.entity.Sheet; import run.halo.app.model.entity.SheetMeta; @@ -32,7 +32,7 @@ public class SheetModel { private final SheetMetaService sheetMetaService; - private final StringCacheStore cacheStore; + private final AbstractStringCacheStore cacheStore; private final ThemeService themeService; @@ -40,7 +40,7 @@ public class SheetModel { public SheetModel(SheetService sheetService, SheetMetaService sheetMetaService, - StringCacheStore cacheStore, + AbstractStringCacheStore cacheStore, ThemeService themeService, OptionService optionService) { this.sheetService = sheetService; diff --git a/src/main/java/run/halo/app/controller/core/CommonController.java b/src/main/java/run/halo/app/controller/core/CommonController.java index 70eb0d02c..a3dbc482e 100644 --- a/src/main/java/run/halo/app/controller/core/CommonController.java +++ b/src/main/java/run/halo/app/controller/core/CommonController.java @@ -15,7 +15,7 @@ import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.util.NestedServletException; -import run.halo.app.exception.HaloException; +import run.halo.app.exception.AbstractHaloException; import run.halo.app.exception.NotFoundException; import run.halo.app.service.OptionService; import run.halo.app.service.ThemeService; @@ -170,8 +170,8 @@ public class CommonController extends AbstractErrorController { if (throwable instanceof NestedServletException) { Throwable rootCause = ((NestedServletException) throwable).getRootCause(); - if (rootCause instanceof HaloException) { - HaloException haloException = (HaloException) rootCause; + if (rootCause instanceof AbstractHaloException) { + AbstractHaloException haloException = (AbstractHaloException) rootCause; request.setAttribute("javax.servlet.error.status_code", haloException.getStatus().value()); request.setAttribute("javax.servlet.error.exception", rootCause); request.setAttribute("javax.servlet.error.message", haloException.getMessage()); diff --git a/src/main/java/run/halo/app/core/ControllerExceptionHandler.java b/src/main/java/run/halo/app/core/ControllerExceptionHandler.java index 0943c4b5f..0962d2a89 100644 --- a/src/main/java/run/halo/app/core/ControllerExceptionHandler.java +++ b/src/main/java/run/halo/app/core/ControllerExceptionHandler.java @@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.servlet.NoHandlerFoundException; -import run.halo.app.exception.HaloException; +import run.halo.app.exception.AbstractHaloException; import run.halo.app.model.support.BaseResponse; import run.halo.app.utils.ExceptionUtils; import run.halo.app.utils.ValidationUtils; @@ -106,8 +106,8 @@ public class ControllerExceptionHandler { return baseResponse; } - @ExceptionHandler(HaloException.class) - public ResponseEntity handleHaloException(HaloException e) { + @ExceptionHandler(AbstractHaloException.class) + public ResponseEntity handleHaloException(AbstractHaloException e) { BaseResponse baseResponse = handleBaseException(e); baseResponse.setStatus(e.getStatus().value()); baseResponse.setData(e.getErrorData()); diff --git a/src/main/java/run/halo/app/core/freemarker/tag/PaginationTagDirective.java b/src/main/java/run/halo/app/core/freemarker/tag/PaginationTagDirective.java index 8484d45b9..5ed84a4dc 100644 --- a/src/main/java/run/halo/app/core/freemarker/tag/PaginationTagDirective.java +++ b/src/main/java/run/halo/app/core/freemarker/tag/PaginationTagDirective.java @@ -14,6 +14,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import static run.halo.app.model.support.HaloConst.URL_SEPARATOR; + /** * @author ryanwang * @date 2020-03-07 @@ -71,7 +73,7 @@ public class PaginationTagDirective implements TemplateDirectiveModel { .append(pathSuffix); if (page == 1) { - prevPageFullPath.append("/"); + prevPageFullPath.append(URL_SEPARATOR); } else { prevPageFullPath.append("/page/") .append(page) @@ -90,9 +92,9 @@ public class PaginationTagDirective implements TemplateDirectiveModel { break; case "archives": - nextPageFullPath.append("/") + nextPageFullPath.append(URL_SEPARATOR) .append(optionService.getArchivesPrefix()); - prevPageFullPath.append("/") + prevPageFullPath.append(URL_SEPARATOR) .append(optionService.getArchivesPrefix()); nextPageFullPath.append("/page/") @@ -108,7 +110,7 @@ public class PaginationTagDirective implements TemplateDirectiveModel { .append(pathSuffix); } - fullPath.append("/") + fullPath.append(URL_SEPARATOR) .append(optionService.getArchivesPrefix()); fullPath.append("/page/"); @@ -124,9 +126,9 @@ public class PaginationTagDirective implements TemplateDirectiveModel { case "search": String keyword = params.get("keyword").toString(); - nextPageFullPath.append("/") + nextPageFullPath.append(URL_SEPARATOR) .append("search"); - prevPageFullPath.append("/") + prevPageFullPath.append(URL_SEPARATOR) .append("search"); nextPageFullPath.append("/page/") @@ -147,7 +149,7 @@ public class PaginationTagDirective implements TemplateDirectiveModel { .append(keyword); } - fullPath.append("/") + fullPath.append(URL_SEPARATOR) .append("search"); fullPath.append("/page/"); @@ -163,13 +165,13 @@ public class PaginationTagDirective implements TemplateDirectiveModel { case "tagPosts": String tagSlug = params.get("slug").toString(); - nextPageFullPath.append("/") + nextPageFullPath.append(URL_SEPARATOR) .append(optionService.getTagsPrefix()) - .append("/") + .append(URL_SEPARATOR) .append(tagSlug); - prevPageFullPath.append("/") + prevPageFullPath.append(URL_SEPARATOR) .append(optionService.getTagsPrefix()) - .append("/") + .append(URL_SEPARATOR) .append(tagSlug); nextPageFullPath.append("/page/") @@ -184,9 +186,9 @@ public class PaginationTagDirective implements TemplateDirectiveModel { .append(pathSuffix); } - fullPath.append("/") + fullPath.append(URL_SEPARATOR) .append(optionService.getTagsPrefix()) - .append("/") + .append(URL_SEPARATOR) .append(tagSlug); fullPath.append("/page/"); @@ -202,13 +204,13 @@ public class PaginationTagDirective implements TemplateDirectiveModel { case "categoryPosts": String categorySlug = params.get("slug").toString(); - nextPageFullPath.append("/") + nextPageFullPath.append(URL_SEPARATOR) .append(optionService.getCategoriesPrefix()) - .append("/") + .append(URL_SEPARATOR) .append(categorySlug); - prevPageFullPath.append("/") + prevPageFullPath.append(URL_SEPARATOR) .append(optionService.getCategoriesPrefix()) - .append("/") + .append(URL_SEPARATOR) .append(categorySlug); nextPageFullPath.append("/page/") @@ -223,9 +225,9 @@ public class PaginationTagDirective implements TemplateDirectiveModel { .append(pathSuffix); } - fullPath.append("/") + fullPath.append(URL_SEPARATOR) .append(optionService.getCategoriesPrefix()) - .append("/") + .append(URL_SEPARATOR) .append(categorySlug); fullPath.append("/page/"); @@ -240,9 +242,9 @@ public class PaginationTagDirective implements TemplateDirectiveModel { break; case "photos": - nextPageFullPath.append("/") + nextPageFullPath.append(URL_SEPARATOR) .append(optionService.getPhotosPrefix()); - prevPageFullPath.append("/") + prevPageFullPath.append(URL_SEPARATOR) .append(optionService.getPhotosPrefix()); nextPageFullPath.append("/page/") @@ -257,7 +259,7 @@ public class PaginationTagDirective implements TemplateDirectiveModel { .append(pathSuffix); } - fullPath.append("/") + fullPath.append(URL_SEPARATOR) .append(optionService.getPhotosPrefix()); fullPath.append("/page/"); @@ -272,9 +274,9 @@ public class PaginationTagDirective implements TemplateDirectiveModel { break; case "journals": - nextPageFullPath.append("/") + nextPageFullPath.append(URL_SEPARATOR) .append(optionService.getJournalsPrefix()); - prevPageFullPath.append("/") + prevPageFullPath.append(URL_SEPARATOR) .append(optionService.getJournalsPrefix()); nextPageFullPath.append("/page/") @@ -289,7 +291,7 @@ public class PaginationTagDirective implements TemplateDirectiveModel { .append(pathSuffix); } - fullPath.append("/") + fullPath.append(URL_SEPARATOR) .append(optionService.getJournalsPrefix()); fullPath.append("/page/"); diff --git a/src/main/java/run/halo/app/event/comment/CommentBaseEvent.java b/src/main/java/run/halo/app/event/comment/AbstractCommentBaseEvent.java similarity index 82% rename from src/main/java/run/halo/app/event/comment/CommentBaseEvent.java rename to src/main/java/run/halo/app/event/comment/AbstractCommentBaseEvent.java index a283fd993..051231fda 100644 --- a/src/main/java/run/halo/app/event/comment/CommentBaseEvent.java +++ b/src/main/java/run/halo/app/event/comment/AbstractCommentBaseEvent.java @@ -10,7 +10,7 @@ import org.springframework.util.Assert; * @author johnniang * @date 19-4-23 */ -public abstract class CommentBaseEvent extends ApplicationEvent { +public abstract class AbstractCommentBaseEvent extends ApplicationEvent { /** * PostComment id. @@ -23,7 +23,7 @@ public abstract class CommentBaseEvent extends ApplicationEvent { * @param source the object on which the event initially occurred (never {@code null}) * @param commentId comment id */ - public CommentBaseEvent(Object source, @NonNull Long commentId) { + public AbstractCommentBaseEvent(Object source, @NonNull Long commentId) { super(source); Assert.notNull(commentId, "PostComment id must not be null"); diff --git a/src/main/java/run/halo/app/event/comment/CommentNewEvent.java b/src/main/java/run/halo/app/event/comment/CommentNewEvent.java index c74f00428..6231cb15f 100644 --- a/src/main/java/run/halo/app/event/comment/CommentNewEvent.java +++ b/src/main/java/run/halo/app/event/comment/CommentNewEvent.java @@ -8,7 +8,7 @@ import org.springframework.lang.NonNull; * @author johnniang * @date 19-4-23 */ -public class CommentNewEvent extends CommentBaseEvent { +public class CommentNewEvent extends AbstractCommentBaseEvent { /** * Create a new ApplicationEvent. diff --git a/src/main/java/run/halo/app/event/comment/CommentReplyEvent.java b/src/main/java/run/halo/app/event/comment/CommentReplyEvent.java index 658cbbeb2..f5af5217b 100644 --- a/src/main/java/run/halo/app/event/comment/CommentReplyEvent.java +++ b/src/main/java/run/halo/app/event/comment/CommentReplyEvent.java @@ -8,7 +8,7 @@ import org.springframework.lang.NonNull; * @author johnniang * @date 19-4-23 */ -public class CommentReplyEvent extends CommentBaseEvent { +public class CommentReplyEvent extends AbstractCommentBaseEvent { /** * Create a new ApplicationEvent. diff --git a/src/main/java/run/halo/app/exception/HaloException.java b/src/main/java/run/halo/app/exception/AbstractHaloException.java similarity index 65% rename from src/main/java/run/halo/app/exception/HaloException.java rename to src/main/java/run/halo/app/exception/AbstractHaloException.java index fd27b59ea..06135131c 100644 --- a/src/main/java/run/halo/app/exception/HaloException.java +++ b/src/main/java/run/halo/app/exception/AbstractHaloException.java @@ -8,22 +8,29 @@ import org.springframework.lang.Nullable; * Base exception of the project. * * @author johnniang + * @author ryan0up + * @date 2019-03-15 */ -public abstract class HaloException extends RuntimeException { +public abstract class AbstractHaloException extends RuntimeException { /** * Error errorData. */ private Object errorData; - public HaloException(String message) { + public AbstractHaloException(String message) { super(message); } - public HaloException(String message, Throwable cause) { + public AbstractHaloException(String message, Throwable cause) { super(message, cause); } + /** + * Http status code + * + * @return {@link HttpStatus} + */ @NonNull public abstract HttpStatus getStatus(); @@ -39,7 +46,7 @@ public abstract class HaloException extends RuntimeException { * @return current exception. */ @NonNull - public HaloException setErrorData(@Nullable Object errorData) { + public AbstractHaloException setErrorData(@Nullable Object errorData) { this.errorData = errorData; return this; } diff --git a/src/main/java/run/halo/app/exception/AuthenticationException.java b/src/main/java/run/halo/app/exception/AuthenticationException.java index 003c37a85..307a97d78 100644 --- a/src/main/java/run/halo/app/exception/AuthenticationException.java +++ b/src/main/java/run/halo/app/exception/AuthenticationException.java @@ -7,7 +7,7 @@ import org.springframework.http.HttpStatus; * * @author johnniang */ -public class AuthenticationException extends HaloException { +public class AuthenticationException extends AbstractHaloException { public AuthenticationException(String message) { super(message); diff --git a/src/main/java/run/halo/app/exception/BadRequestException.java b/src/main/java/run/halo/app/exception/BadRequestException.java index 108441da3..8a336c5b1 100644 --- a/src/main/java/run/halo/app/exception/BadRequestException.java +++ b/src/main/java/run/halo/app/exception/BadRequestException.java @@ -7,7 +7,7 @@ import org.springframework.http.HttpStatus; * * @author johnniang */ -public class BadRequestException extends HaloException { +public class BadRequestException extends AbstractHaloException { public BadRequestException(String message) { super(message); diff --git a/src/main/java/run/halo/app/exception/BeanUtilsException.java b/src/main/java/run/halo/app/exception/BeanUtilsException.java index ea30d2792..7fbcb0d5f 100644 --- a/src/main/java/run/halo/app/exception/BeanUtilsException.java +++ b/src/main/java/run/halo/app/exception/BeanUtilsException.java @@ -7,7 +7,7 @@ import org.springframework.http.HttpStatus; * * @author johnniang */ -public class BeanUtilsException extends HaloException { +public class BeanUtilsException extends AbstractHaloException { public BeanUtilsException(String message) { super(message); diff --git a/src/main/java/run/halo/app/exception/ForbiddenException.java b/src/main/java/run/halo/app/exception/ForbiddenException.java index ef30138d0..5c6e19f68 100644 --- a/src/main/java/run/halo/app/exception/ForbiddenException.java +++ b/src/main/java/run/halo/app/exception/ForbiddenException.java @@ -7,7 +7,7 @@ import org.springframework.http.HttpStatus; * * @author johnniang */ -public class ForbiddenException extends HaloException { +public class ForbiddenException extends AbstractHaloException { public ForbiddenException(String message) { super(message); diff --git a/src/main/java/run/halo/app/exception/NotFoundException.java b/src/main/java/run/halo/app/exception/NotFoundException.java index d35854716..e9df11198 100644 --- a/src/main/java/run/halo/app/exception/NotFoundException.java +++ b/src/main/java/run/halo/app/exception/NotFoundException.java @@ -7,7 +7,7 @@ import org.springframework.http.HttpStatus; * * @author johnniang */ -public class NotFoundException extends HaloException { +public class NotFoundException extends AbstractHaloException { public NotFoundException(String message) { super(message); diff --git a/src/main/java/run/halo/app/exception/ServiceException.java b/src/main/java/run/halo/app/exception/ServiceException.java index 7049abf39..7a3444a10 100644 --- a/src/main/java/run/halo/app/exception/ServiceException.java +++ b/src/main/java/run/halo/app/exception/ServiceException.java @@ -7,7 +7,7 @@ import org.springframework.http.HttpStatus; * * @author johnniang */ -public class ServiceException extends HaloException { +public class ServiceException extends AbstractHaloException { public ServiceException(String message) { super(message); diff --git a/src/main/java/run/halo/app/handler/file/AliOssFileHandler.java b/src/main/java/run/halo/app/handler/file/AliOssFileHandler.java index 136b43ef7..7cd5ec443 100644 --- a/src/main/java/run/halo/app/handler/file/AliOssFileHandler.java +++ b/src/main/java/run/halo/app/handler/file/AliOssFileHandler.java @@ -21,6 +21,8 @@ import run.halo.app.utils.ImageUtils; import javax.imageio.ImageReader; import java.util.Objects; +import static run.halo.app.model.support.HaloConst.URL_SEPARATOR; + /** * Ali oss file handler. * @@ -60,12 +62,12 @@ public class AliOssFileHandler implements FileHandler { if (StringUtils.isNotEmpty(domain)) { basePath.append(domain) - .append("/"); + .append(URL_SEPARATOR); } else { basePath.append(bucketName) .append(".") .append(endPoint) - .append("/"); + .append(URL_SEPARATOR); } try { @@ -76,7 +78,7 @@ public class AliOssFileHandler implements FileHandler { if (StringUtils.isNotEmpty(source)) { upFilePath.append(source) - .append("/"); + .append(URL_SEPARATOR); } upFilePath.append(basename) diff --git a/src/main/java/run/halo/app/handler/file/QiniuOssFileHandler.java b/src/main/java/run/halo/app/handler/file/QiniuOssFileHandler.java index 105d6810f..b29f8a417 100644 --- a/src/main/java/run/halo/app/handler/file/QiniuOssFileHandler.java +++ b/src/main/java/run/halo/app/handler/file/QiniuOssFileHandler.java @@ -1,14 +1,16 @@ package run.halo.app.handler.file; import com.qiniu.common.QiniuException; -import com.qiniu.common.Zone; import com.qiniu.http.Response; import com.qiniu.storage.BucketManager; import com.qiniu.storage.Configuration; +import com.qiniu.storage.Region; import com.qiniu.storage.UploadManager; import com.qiniu.storage.persistent.FileRecorder; import com.qiniu.util.Auth; import com.qiniu.util.StringMap; +import lombok.Data; +import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.http.MediaType; @@ -18,7 +20,6 @@ import org.springframework.web.multipart.MultipartFile; import run.halo.app.exception.FileOperationException; import run.halo.app.model.enums.AttachmentType; import run.halo.app.model.properties.QiniuOssProperties; -import run.halo.app.model.support.QiNiuPutSet; import run.halo.app.model.support.UploadResult; import run.halo.app.service.OptionService; import run.halo.app.utils.FilenameUtils; @@ -31,6 +32,7 @@ import java.nio.file.Paths; import java.util.Objects; import static run.halo.app.handler.file.FileHandler.isImageType; +import static run.halo.app.model.support.HaloConst.URL_SEPARATOR; /** * Qiniu oss file handler. @@ -53,8 +55,8 @@ public class QiniuOssFileHandler implements FileHandler { public UploadResult upload(MultipartFile file) { Assert.notNull(file, "Multipart file must not be null"); - // Get all config - Zone zone = optionService.getQnYunZone(); + Region region = optionService.getQiniuRegion(); + String accessKey = optionService.getByPropertyOfNonNull(QiniuOssProperties.OSS_ACCESS_KEY).toString(); String secretKey = optionService.getByPropertyOfNonNull(QiniuOssProperties.OSS_SECRET_KEY).toString(); String bucket = optionService.getByPropertyOfNonNull(QiniuOssProperties.OSS_BUCKET).toString(); @@ -65,26 +67,22 @@ public class QiniuOssFileHandler implements FileHandler { String thumbnailStyleRule = optionService.getByPropertyOrDefault(QiniuOssProperties.OSS_THUMBNAIL_STYLE_RULE, String.class, ""); // Create configuration - Configuration configuration = new Configuration(zone); + Configuration configuration = new Configuration(region); // Create auth Auth auth = Auth.create(accessKey, secretKey); // Build put plicy StringMap putPolicy = new StringMap(); - putPolicy.put("returnBody", "{\"size\":$(fsize), " + - "\"width\":$(imageInfo.width), " + - "\"height\":$(imageInfo.height)," + - " \"key\":\"$(key)\", " + - "\"hash\":\"$(etag)\"}"); + putPolicy.put("returnBody", "{\"key\":\"$(key)\",\"hash\":\"$(etag)\",\"size\":$(fsize),\"width\":$(imageInfo.width),\"height\":$(imageInfo.height)}"); // Get upload token - String uploadToken = auth.uploadToken(bucket, null, 3600, putPolicy); + String uploadToken = auth.uploadToken(bucket, null, 60 * 60, putPolicy); // Create temp path Path tmpPath = Paths.get(System.getProperty("java.io.tmpdir"), bucket); StringBuilder basePath = new StringBuilder(protocol) .append(domain) - .append("/"); + .append(URL_SEPARATOR); try { String basename = FilenameUtils.getBasename(Objects.requireNonNull(file.getOriginalFilename())); @@ -93,7 +91,7 @@ public class QiniuOssFileHandler implements FileHandler { StringBuilder upFilePath = new StringBuilder(); if (StringUtils.isNotEmpty(source)) { upFilePath.append(source) - .append("/"); + .append(URL_SEPARATOR); } upFilePath.append(basename) .append("_") @@ -109,14 +107,12 @@ public class QiniuOssFileHandler implements FileHandler { Response response = uploadManager.put(file.getInputStream(), upFilePath.toString(), uploadToken, null, null); if (log.isDebugEnabled()) { - log.debug("QnYun response: [{}]", response.toString()); - log.debug("QnYun response body: [{}]", response.bodyString()); + log.debug("Qiniu oss response: [{}]", response.toString()); + log.debug("Qiniu oss response body: [{}]", response.bodyString()); } - response.jsonToObject(QiNiuPutSet.class); - // Convert response - QiNiuPutSet putSet = JsonUtils.jsonToObject(response.bodyString(), QiNiuPutSet.class); + PutSet putSet = JsonUtils.jsonToObject(response.bodyString(), PutSet.class); // Get file full path String filePath = StringUtils.join(basePath.toString(), upFilePath.toString()); @@ -143,7 +139,7 @@ public class QiniuOssFileHandler implements FileHandler { return result; } catch (IOException e) { if (e instanceof QiniuException) { - log.error("QnYun error response: [{}]", ((QiniuException) e).response); + log.error("Qiniu oss error response: [{}]", ((QiniuException) e).response); } throw new FileOperationException("上传附件 " + file.getOriginalFilename() + " 到七牛云失败", e); @@ -154,14 +150,14 @@ public class QiniuOssFileHandler implements FileHandler { public void delete(String key) { Assert.notNull(key, "File key must not be blank"); - // Get all config - Zone zone = optionService.getQnYunZone(); + Region region = optionService.getQiniuRegion(); + String accessKey = optionService.getByPropertyOfNonNull(QiniuOssProperties.OSS_ACCESS_KEY).toString(); String secretKey = optionService.getByPropertyOfNonNull(QiniuOssProperties.OSS_SECRET_KEY).toString(); String bucket = optionService.getByPropertyOfNonNull(QiniuOssProperties.OSS_BUCKET).toString(); // Create configuration - Configuration configuration = new Configuration(zone); + Configuration configuration = new Configuration(region); // Create auth Auth auth = Auth.create(accessKey, secretKey); @@ -169,9 +165,12 @@ public class QiniuOssFileHandler implements FileHandler { BucketManager bucketManager = new BucketManager(auth, configuration); try { - bucketManager.delete(bucket, key); + Response response = bucketManager.delete(bucket, key); + if (!response.isOK()) { + log.warn("附件 " + key + " 从七牛云删除失败"); + } } catch (QiniuException e) { - log.error("QnYun error response: [{}]", e.response); + log.error("Qiniu oss error response: [{}]", e.response); throw new FileOperationException("附件 " + key + " 从七牛云删除失败", e); } } @@ -180,4 +179,20 @@ public class QiniuOssFileHandler implements FileHandler { public AttachmentType getAttachmentType() { return AttachmentType.QINIUOSS; } + + @Data + @NoArgsConstructor + private static class PutSet { + + public String hash; + + public String key; + + private Long size; + + private Integer width; + + private Integer height; + } } + diff --git a/src/main/java/run/halo/app/handler/file/TencentCosFileHandler.java b/src/main/java/run/halo/app/handler/file/TencentCosFileHandler.java index 199499950..a7c65e9d1 100644 --- a/src/main/java/run/halo/app/handler/file/TencentCosFileHandler.java +++ b/src/main/java/run/halo/app/handler/file/TencentCosFileHandler.java @@ -25,6 +25,8 @@ import run.halo.app.utils.ImageUtils; import javax.imageio.ImageReader; import java.util.Objects; +import static run.halo.app.model.support.HaloConst.URL_SEPARATOR; + /** * Tencent cos file handler. * @@ -68,13 +70,13 @@ public class TencentCosFileHandler implements FileHandler { if (StringUtils.isNotEmpty(domain)) { basePath.append(domain) - .append("/"); + .append(URL_SEPARATOR); } else { basePath.append(bucketName) .append(".cos.") .append(region) .append(".myqcloud.com") - .append("/"); + .append(URL_SEPARATOR); } try { @@ -85,7 +87,7 @@ public class TencentCosFileHandler implements FileHandler { if (StringUtils.isNotEmpty(source)) { upFilePath.append(source) - .append("/"); + .append(URL_SEPARATOR); } upFilePath.append(basename) diff --git a/src/main/java/run/halo/app/listener/comment/CommentEventListener.java b/src/main/java/run/halo/app/listener/comment/CommentEventListener.java index 1cf69fd18..fccb8937d 100644 --- a/src/main/java/run/halo/app/listener/comment/CommentEventListener.java +++ b/src/main/java/run/halo/app/listener/comment/CommentEventListener.java @@ -2,8 +2,8 @@ package run.halo.app.listener.comment; import cn.hutool.core.lang.Validator; import cn.hutool.core.text.StrBuilder; -import cn.hutool.core.util.StrUtil; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; @@ -175,7 +175,7 @@ public class CommentEventListener { PostComment baseComment = postCommentService.getById(postComment.getParentId()); - if (StrUtil.isEmpty(baseComment.getEmail()) && !Validator.isEmail(baseComment.getEmail())) { + if (StringUtils.isEmpty(baseComment.getEmail()) && !Validator.isEmail(baseComment.getEmail())) { return; } @@ -205,7 +205,7 @@ public class CommentEventListener { SheetComment baseComment = sheetCommentService.getById(sheetComment.getParentId()); - if (StrUtil.isEmpty(baseComment.getEmail()) && !Validator.isEmail(baseComment.getEmail())) { + if (StringUtils.isEmpty(baseComment.getEmail()) && !Validator.isEmail(baseComment.getEmail())) { return; } @@ -234,7 +234,7 @@ public class CommentEventListener { JournalComment baseComment = journalCommentService.getById(journalComment.getParentId()); - if (StrUtil.isEmpty(baseComment.getEmail()) && !Validator.isEmail(baseComment.getEmail())) { + if (StringUtils.isEmpty(baseComment.getEmail()) && !Validator.isEmail(baseComment.getEmail())) { return; } diff --git a/src/main/java/run/halo/app/listener/theme/ThemeUpdatedListener.java b/src/main/java/run/halo/app/listener/theme/ThemeUpdatedListener.java index 9c8d0f7f3..adba11b32 100644 --- a/src/main/java/run/halo/app/listener/theme/ThemeUpdatedListener.java +++ b/src/main/java/run/halo/app/listener/theme/ThemeUpdatedListener.java @@ -2,7 +2,7 @@ package run.halo.app.listener.theme; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Component; -import run.halo.app.cache.StringCacheStore; +import run.halo.app.cache.AbstractStringCacheStore; import run.halo.app.event.options.OptionUpdatedEvent; import run.halo.app.event.theme.ThemeUpdatedEvent; import run.halo.app.service.ThemeService; @@ -16,9 +16,9 @@ import run.halo.app.service.ThemeService; @Component public class ThemeUpdatedListener { - private final StringCacheStore cacheStore; + private final AbstractStringCacheStore cacheStore; - public ThemeUpdatedListener(StringCacheStore cacheStore) { + public ThemeUpdatedListener(AbstractStringCacheStore cacheStore) { this.cacheStore = cacheStore; } diff --git a/src/main/java/run/halo/app/model/dto/post/BasePostSimpleDTO.java b/src/main/java/run/halo/app/model/dto/post/BasePostSimpleDTO.java index 88b6a4a82..b9ed8175e 100644 --- a/src/main/java/run/halo/app/model/dto/post/BasePostSimpleDTO.java +++ b/src/main/java/run/halo/app/model/dto/post/BasePostSimpleDTO.java @@ -18,7 +18,7 @@ public class BasePostSimpleDTO extends BasePostMinimalDTO { private String thumbnail; - private Long visits = 0L; + private Long visits; private Boolean disallowComment; @@ -26,7 +26,7 @@ public class BasePostSimpleDTO extends BasePostMinimalDTO { private String template; - private Integer topPriority = 0; + private Integer topPriority; - private Long likes = 0L; + private Long likes; } diff --git a/src/main/java/run/halo/app/model/enums/InputType.java b/src/main/java/run/halo/app/model/enums/InputType.java index 392fc2331..b2640b3fc 100644 --- a/src/main/java/run/halo/app/model/enums/InputType.java +++ b/src/main/java/run/halo/app/model/enums/InputType.java @@ -11,18 +11,39 @@ import org.springframework.lang.Nullable; */ public enum InputType { + /** + * Text input type + */ TEXT, + /** + * Number input type + */ NUMBER, + /** + * Radio box input type + */ RADIO, + /** + * Select input type + */ SELECT, + /** + * Textarea input type + */ TEXTAREA, + /** + * Color picker input type + */ COLOR, + /** + * Attachment picker input type + */ ATTACHMENT; /** diff --git a/src/main/java/run/halo/app/model/enums/LogType.java b/src/main/java/run/halo/app/model/enums/LogType.java index 11b058d79..3c3ec4438 100644 --- a/src/main/java/run/halo/app/model/enums/LogType.java +++ b/src/main/java/run/halo/app/model/enums/LogType.java @@ -7,17 +7,64 @@ package run.halo.app.model.enums; */ public enum LogType implements ValueEnum { + /** + * Blog initialization + */ BLOG_INITIALIZED(0), + + /** + * Post published + */ POST_PUBLISHED(5), + + /** + * Post edited + */ POST_EDITED(15), + + /** + * Post deleted + */ POST_DELETED(20), + + /** + * Logged in + */ LOGGED_IN(25), + + /** + * Logged out + */ LOGGED_OUT(30), + + /** + * Logged failed. + */ LOGIN_FAILED(35), + + /** + * Updated the blogger password + */ PASSWORD_UPDATED(40), + + /** + * Updated the blogger profile + */ PROFILE_UPDATED(45), + + /** + * Sheet published + */ SHEET_PUBLISHED(50), + + /** + * Sheet edited + */ SHEET_EDITED(55), + + /** + * Sheet deleted + */ SHEET_DELETED(60); private final Integer value; diff --git a/src/main/java/run/halo/app/model/enums/Mode.java b/src/main/java/run/halo/app/model/enums/Mode.java index a8eaceca6..0905d4830 100644 --- a/src/main/java/run/halo/app/model/enums/Mode.java +++ b/src/main/java/run/halo/app/model/enums/Mode.java @@ -11,9 +11,25 @@ import org.springframework.lang.Nullable; * @date 19-6-10 */ public enum Mode { + + /** + * Production mode + */ PRODUCTION, + + /** + * Develop mode + */ DEVELOPMENT, + + /** + * Demo mode + */ DEMO, + + /** + * Test mode + */ TEST; /** diff --git a/src/main/java/run/halo/app/model/properties/AliOssProperties.java b/src/main/java/run/halo/app/model/properties/AliOssProperties.java index defbd2e24..f5cb7ed49 100644 --- a/src/main/java/run/halo/app/model/properties/AliOssProperties.java +++ b/src/main/java/run/halo/app/model/properties/AliOssProperties.java @@ -1,5 +1,7 @@ package run.halo.app.model.properties; +import run.halo.app.model.support.HaloConst; + /** * Ali yun oss properties. * @@ -12,7 +14,7 @@ public enum AliOssProperties implements PropertyEnum { /** * Aliyun oss domain protocol */ - OSS_PROTOCOL("oss_ali_domain_protocol", String.class, "https://"), + OSS_PROTOCOL("oss_ali_domain_protocol", String.class, HaloConst.PROTOCOL_HTTPS), /** * Aliyun oss domain diff --git a/src/main/java/run/halo/app/model/properties/BaiduBosProperties.java b/src/main/java/run/halo/app/model/properties/BaiduBosProperties.java index 8b4981708..3e7203dc9 100644 --- a/src/main/java/run/halo/app/model/properties/BaiduBosProperties.java +++ b/src/main/java/run/halo/app/model/properties/BaiduBosProperties.java @@ -1,5 +1,7 @@ package run.halo.app.model.properties; +import run.halo.app.model.support.HaloConst; + /** * Baidu bos properties. * @@ -12,7 +14,7 @@ public enum BaiduBosProperties implements PropertyEnum { /** * Baidu bos domain protocol. */ - BOS_PROTOCOL("bos_baidu_domain_protocol", String.class, "https://"), + BOS_PROTOCOL("bos_baidu_domain_protocol", String.class, HaloConst.PROTOCOL_HTTPS), /** * Baidu bos domain. diff --git a/src/main/java/run/halo/app/model/properties/EmailProperties.java b/src/main/java/run/halo/app/model/properties/EmailProperties.java index 2322073ff..acefba52e 100644 --- a/src/main/java/run/halo/app/model/properties/EmailProperties.java +++ b/src/main/java/run/halo/app/model/properties/EmailProperties.java @@ -8,18 +8,39 @@ package run.halo.app.model.properties; */ public enum EmailProperties implements PropertyEnum { + /** + * Email sender host + */ HOST("email_host", String.class, ""), + /** + * Email sender protocol + */ PROTOCOL("email_protocol", String.class, "smtp"), + /** + * SSL port + */ SSL_PORT("email_ssl_port", Integer.class, "465"), + /** + * Email Sender username + */ USERNAME("email_username", String.class, ""), + /** + * Email Sender password + */ PASSWORD("email_password", String.class, ""), + /** + * Email Sender name + */ FROM_NAME("email_from_name", String.class, ""), + /** + * Is enabled email sender + */ ENABLED("email_enabled", Boolean.class, "false"); private final String value; diff --git a/src/main/java/run/halo/app/model/properties/QiniuOssProperties.java b/src/main/java/run/halo/app/model/properties/QiniuOssProperties.java index 3e26edcf0..35785f494 100644 --- a/src/main/java/run/halo/app/model/properties/QiniuOssProperties.java +++ b/src/main/java/run/halo/app/model/properties/QiniuOssProperties.java @@ -1,5 +1,7 @@ package run.halo.app.model.properties; +import run.halo.app.model.support.HaloConst; + /** * Qiniu oss properties. * @@ -32,7 +34,7 @@ public enum QiniuOssProperties implements PropertyEnum { /** * Qiniu oss domain protocol. */ - OSS_PROTOCOL("oss_qiniu_domain_protocol", String.class, "https://"), + OSS_PROTOCOL("oss_qiniu_domain_protocol", String.class, HaloConst.PROTOCOL_HTTPS), /** * Qiniu oss domain. diff --git a/src/main/java/run/halo/app/model/properties/TencentCosProperties.java b/src/main/java/run/halo/app/model/properties/TencentCosProperties.java index 348ad5d3f..2e74a04d2 100644 --- a/src/main/java/run/halo/app/model/properties/TencentCosProperties.java +++ b/src/main/java/run/halo/app/model/properties/TencentCosProperties.java @@ -1,5 +1,7 @@ package run.halo.app.model.properties; +import run.halo.app.model.support.HaloConst; + /** * Tencent cos properties. * @@ -12,7 +14,7 @@ public enum TencentCosProperties implements PropertyEnum { /** * Tencent cos domain protocol. */ - COS_PROTOCOL("cos_tencent_domain_protocol", String.class, "https://"), + COS_PROTOCOL("cos_tencent_domain_protocol", String.class, HaloConst.PROTOCOL_HTTPS), /** * Tencent cos domain. diff --git a/src/main/java/run/halo/app/model/properties/UpOssProperties.java b/src/main/java/run/halo/app/model/properties/UpOssProperties.java index b8e2a5993..736d9cfbf 100644 --- a/src/main/java/run/halo/app/model/properties/UpOssProperties.java +++ b/src/main/java/run/halo/app/model/properties/UpOssProperties.java @@ -1,5 +1,7 @@ package run.halo.app.model.properties; +import run.halo.app.model.support.HaloConst; + /** * Upyun oss properties. * @@ -27,7 +29,7 @@ public enum UpOssProperties implements PropertyEnum { /** * upyun oss domain protocol */ - OSS_PROTOCOL("oss_upyun_domain_protocol", String.class, "https://"), + OSS_PROTOCOL("oss_upyun_domain_protocol", String.class, HaloConst.PROTOCOL_HTTPS), /** * upyun oss domain diff --git a/src/main/java/run/halo/app/model/support/BackupDto.java b/src/main/java/run/halo/app/model/support/BackupDto.java deleted file mode 100644 index 50bce5e64..000000000 --- a/src/main/java/run/halo/app/model/support/BackupDto.java +++ /dev/null @@ -1,43 +0,0 @@ -package run.halo.app.model.support; - -import lombok.Data; - -import java.util.Date; - -/** - *
- *     备份信息
- * 
- * - * @author ryanwang - * @date 2018/6/4 - */ -@Data -@Deprecated -public class BackupDto { - - /** - * 文件名 - */ - private String fileName; - - /** - * 创建时间 - */ - private Date createAt; - - /** - * 文件大小 - */ - private String fileSize; - - /** - * 文件类型 - */ - private String fileType; - - /** - * 备份类型 - */ - private String backupType; -} diff --git a/src/main/java/run/halo/app/model/support/HaloConst.java b/src/main/java/run/halo/app/model/support/HaloConst.java index 7160e0192..c80fb6092 100644 --- a/src/main/java/run/halo/app/model/support/HaloConst.java +++ b/src/main/java/run/halo/app/model/support/HaloConst.java @@ -24,6 +24,12 @@ public class HaloConst { */ public final static String TEMP_DIR = System.getProperties().getProperty("java.io.tmpdir"); + public final static String PROTOCOL_HTTPS = "https://"; + + public final static String PROTOCOL_HTTP = "http://"; + + public final static String URL_SEPARATOR = "/"; + /** * Halo backup prefix. */ diff --git a/src/main/java/run/halo/app/model/support/QiNiuPutSet.java b/src/main/java/run/halo/app/model/support/QiNiuPutSet.java deleted file mode 100644 index 7565c71bf..000000000 --- a/src/main/java/run/halo/app/model/support/QiNiuPutSet.java +++ /dev/null @@ -1,40 +0,0 @@ -package run.halo.app.model.support; - -import lombok.Data; - -/** - *
- *     七牛上传自定义凭证回调解析
- * 
- * - * @author : Yawn - * @date 2018/12/3 - */ -@Data -public class QiNiuPutSet { - - /** - * 文件hash值 - */ - public String hash; - - /** - * 文件名 - */ - public String key; - - /** - * 图片大小 - */ - private Long size; - - /** - * 长 - */ - private Integer width; - - /** - * 宽 - */ - private Integer height; -} diff --git a/src/main/java/run/halo/app/security/filter/AbstractAuthenticationFilter.java b/src/main/java/run/halo/app/security/filter/AbstractAuthenticationFilter.java index 1615c6644..26f5b7df6 100644 --- a/src/main/java/run/halo/app/security/filter/AbstractAuthenticationFilter.java +++ b/src/main/java/run/halo/app/security/filter/AbstractAuthenticationFilter.java @@ -8,11 +8,11 @@ import org.springframework.util.AntPathMatcher; import org.springframework.util.Assert; import org.springframework.web.filter.OncePerRequestFilter; import org.springframework.web.util.UrlPathHelper; -import run.halo.app.cache.StringCacheStore; +import run.halo.app.cache.AbstractStringCacheStore; import run.halo.app.config.properties.HaloProperties; +import run.halo.app.exception.AbstractHaloException; import run.halo.app.exception.BadRequestException; import run.halo.app.exception.ForbiddenException; -import run.halo.app.exception.HaloException; import run.halo.app.exception.NotInstallException; import run.halo.app.model.enums.Mode; import run.halo.app.model.properties.PrimaryProperties; @@ -44,7 +44,7 @@ public abstract class AbstractAuthenticationFilter extends OncePerRequestFilter protected final AntPathMatcher antPathMatcher; protected final HaloProperties haloProperties; protected final OptionService optionService; - protected final StringCacheStore cacheStore; + protected final AbstractStringCacheStore cacheStore; private final UrlPathHelper urlPathHelper = new UrlPathHelper(); private OneTimeTokenService oneTimeTokenService; @@ -59,7 +59,7 @@ public abstract class AbstractAuthenticationFilter extends OncePerRequestFilter AbstractAuthenticationFilter(HaloProperties haloProperties, OptionService optionService, - StringCacheStore cacheStore, + AbstractStringCacheStore cacheStore, OneTimeTokenService oneTimeTokenService) { this.haloProperties = haloProperties; this.optionService = optionService; @@ -189,7 +189,7 @@ public abstract class AbstractAuthenticationFilter extends OncePerRequestFilter // Do authenticate doAuthenticate(request, response, filterChain); - } catch (HaloException e) { + } catch (AbstractHaloException e) { getFailureHandler().onFailure(request, response, e); } finally { SecurityContextHolder.clearContext(); diff --git a/src/main/java/run/halo/app/security/filter/AdminAuthenticationFilter.java b/src/main/java/run/halo/app/security/filter/AdminAuthenticationFilter.java index 3e3479d44..56c4adcd1 100644 --- a/src/main/java/run/halo/app/security/filter/AdminAuthenticationFilter.java +++ b/src/main/java/run/halo/app/security/filter/AdminAuthenticationFilter.java @@ -6,7 +6,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.core.annotation.Order; import org.springframework.lang.NonNull; import org.springframework.stereotype.Component; -import run.halo.app.cache.StringCacheStore; +import run.halo.app.cache.AbstractStringCacheStore; import run.halo.app.config.properties.HaloProperties; import run.halo.app.exception.AuthenticationException; import run.halo.app.model.entity.User; @@ -44,7 +44,7 @@ public class AdminAuthenticationFilter extends AbstractAuthenticationFilter { private final UserService userService; - public AdminAuthenticationFilter(StringCacheStore cacheStore, + public AdminAuthenticationFilter(AbstractStringCacheStore cacheStore, UserService userService, HaloProperties haloProperties, OptionService optionService, diff --git a/src/main/java/run/halo/app/security/filter/ApiAuthenticationFilter.java b/src/main/java/run/halo/app/security/filter/ApiAuthenticationFilter.java index 24ae01ca3..84feed6cf 100644 --- a/src/main/java/run/halo/app/security/filter/ApiAuthenticationFilter.java +++ b/src/main/java/run/halo/app/security/filter/ApiAuthenticationFilter.java @@ -6,7 +6,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.core.annotation.Order; import org.springframework.lang.NonNull; import org.springframework.stereotype.Component; -import run.halo.app.cache.StringCacheStore; +import run.halo.app.cache.AbstractStringCacheStore; import run.halo.app.config.properties.HaloProperties; import run.halo.app.exception.AuthenticationException; import run.halo.app.exception.ForbiddenException; @@ -40,7 +40,7 @@ public class ApiAuthenticationFilter extends AbstractAuthenticationFilter { public ApiAuthenticationFilter(HaloProperties haloProperties, OptionService optionService, - StringCacheStore cacheStore, + AbstractStringCacheStore cacheStore, OneTimeTokenService oneTimeTokenService, ObjectMapper objectMapper) { super(haloProperties, optionService, cacheStore, oneTimeTokenService); diff --git a/src/main/java/run/halo/app/security/filter/ContentFilter.java b/src/main/java/run/halo/app/security/filter/ContentFilter.java index b4039e6e8..e5453184e 100644 --- a/src/main/java/run/halo/app/security/filter/ContentFilter.java +++ b/src/main/java/run/halo/app/security/filter/ContentFilter.java @@ -2,7 +2,7 @@ package run.halo.app.security.filter; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; -import run.halo.app.cache.StringCacheStore; +import run.halo.app.cache.AbstractStringCacheStore; import run.halo.app.config.properties.HaloProperties; import run.halo.app.security.handler.ContentAuthenticationFailureHandler; import run.halo.app.security.service.OneTimeTokenService; @@ -27,7 +27,7 @@ public class ContentFilter extends AbstractAuthenticationFilter { public ContentFilter(HaloProperties haloProperties, OptionService optionService, - StringCacheStore cacheStore, + AbstractStringCacheStore cacheStore, OneTimeTokenService oneTimeTokenService) { super(haloProperties, optionService, cacheStore, oneTimeTokenService); diff --git a/src/main/java/run/halo/app/security/handler/AuthenticationFailureHandler.java b/src/main/java/run/halo/app/security/handler/AuthenticationFailureHandler.java index 2c5784363..914c967ed 100644 --- a/src/main/java/run/halo/app/security/handler/AuthenticationFailureHandler.java +++ b/src/main/java/run/halo/app/security/handler/AuthenticationFailureHandler.java @@ -1,6 +1,6 @@ package run.halo.app.security.handler; -import run.halo.app.exception.HaloException; +import run.halo.app.exception.AbstractHaloException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -23,5 +23,5 @@ public interface AuthenticationFailureHandler { * @throws IOException io exception * @throws ServletException service exception */ - void onFailure(HttpServletRequest request, HttpServletResponse response, HaloException exception) throws IOException, ServletException; + void onFailure(HttpServletRequest request, HttpServletResponse response, AbstractHaloException exception) throws IOException, ServletException; } diff --git a/src/main/java/run/halo/app/security/handler/ContentAuthenticationFailureHandler.java b/src/main/java/run/halo/app/security/handler/ContentAuthenticationFailureHandler.java index 4e863402d..555eb9bcc 100644 --- a/src/main/java/run/halo/app/security/handler/ContentAuthenticationFailureHandler.java +++ b/src/main/java/run/halo/app/security/handler/ContentAuthenticationFailureHandler.java @@ -1,6 +1,6 @@ package run.halo.app.security.handler; -import run.halo.app.exception.HaloException; +import run.halo.app.exception.AbstractHaloException; import run.halo.app.exception.NotInstallException; import javax.servlet.ServletException; @@ -17,7 +17,7 @@ import java.io.IOException; public class ContentAuthenticationFailureHandler implements AuthenticationFailureHandler { @Override - public void onFailure(HttpServletRequest request, HttpServletResponse response, HaloException exception) throws IOException, ServletException { + public void onFailure(HttpServletRequest request, HttpServletResponse response, AbstractHaloException exception) throws IOException, ServletException { if (exception instanceof NotInstallException) { response.sendRedirect(request.getContextPath() + "/install"); return; diff --git a/src/main/java/run/halo/app/security/handler/DefaultAuthenticationFailureHandler.java b/src/main/java/run/halo/app/security/handler/DefaultAuthenticationFailureHandler.java index ada70d584..8cc0bd442 100644 --- a/src/main/java/run/halo/app/security/handler/DefaultAuthenticationFailureHandler.java +++ b/src/main/java/run/halo/app/security/handler/DefaultAuthenticationFailureHandler.java @@ -5,7 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import lombok.extern.slf4j.Slf4j; import org.springframework.http.MediaType; import org.springframework.util.Assert; -import run.halo.app.exception.HaloException; +import run.halo.app.exception.AbstractHaloException; import run.halo.app.model.support.BaseResponse; import run.halo.app.utils.ExceptionUtils; import run.halo.app.utils.JsonUtils; @@ -32,7 +32,7 @@ public class DefaultAuthenticationFailureHandler implements AuthenticationFailur } @Override - public void onFailure(HttpServletRequest request, HttpServletResponse response, HaloException exception) throws IOException, ServletException { + public void onFailure(HttpServletRequest request, HttpServletResponse response, AbstractHaloException exception) throws IOException, ServletException { log.warn("Handle unsuccessful authentication, ip: [{}]", ServletUtil.getClientIP(request)); log.error("Authentication failure", exception); diff --git a/src/main/java/run/halo/app/security/service/impl/OneTimeTokenServiceImpl.java b/src/main/java/run/halo/app/security/service/impl/OneTimeTokenServiceImpl.java index 125f1d800..765b5bd64 100644 --- a/src/main/java/run/halo/app/security/service/impl/OneTimeTokenServiceImpl.java +++ b/src/main/java/run/halo/app/security/service/impl/OneTimeTokenServiceImpl.java @@ -2,7 +2,7 @@ package run.halo.app.security.service.impl; import org.springframework.stereotype.Service; import org.springframework.util.Assert; -import run.halo.app.cache.StringCacheStore; +import run.halo.app.cache.AbstractStringCacheStore; import run.halo.app.security.service.OneTimeTokenService; import run.halo.app.utils.HaloUtils; @@ -22,9 +22,9 @@ public class OneTimeTokenServiceImpl implements OneTimeTokenService { */ public static final int OTT_EXPIRED_DAY = 1; - private final StringCacheStore cacheStore; + private final AbstractStringCacheStore cacheStore; - public OneTimeTokenServiceImpl(StringCacheStore cacheStore) { + public OneTimeTokenServiceImpl(AbstractStringCacheStore cacheStore) { this.cacheStore = cacheStore; } diff --git a/src/main/java/run/halo/app/service/OptionService.java b/src/main/java/run/halo/app/service/OptionService.java index ac8f8bcd8..8dd65f2c3 100755 --- a/src/main/java/run/halo/app/service/OptionService.java +++ b/src/main/java/run/halo/app/service/OptionService.java @@ -1,6 +1,7 @@ package run.halo.app.service; import com.qiniu.common.Zone; +import com.qiniu.storage.Region; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.lang.NonNull; @@ -328,8 +329,17 @@ public interface OptionService extends CrudService { * @return qiniu zone */ @NonNull + @Deprecated Zone getQnYunZone(); + /** + * Get qiniu oss region. + * + * @return qiniu region + */ + @NonNull + Region getQiniuRegion(); + /** * Gets locale. * diff --git a/src/main/java/run/halo/app/service/impl/AdminServiceImpl.java b/src/main/java/run/halo/app/service/impl/AdminServiceImpl.java index acd89c396..d4d77a181 100644 --- a/src/main/java/run/halo/app/service/impl/AdminServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/AdminServiceImpl.java @@ -12,7 +12,7 @@ import org.springframework.lang.NonNull; import org.springframework.stereotype.Service; import org.springframework.util.Assert; import org.springframework.web.client.RestTemplate; -import run.halo.app.cache.StringCacheStore; +import run.halo.app.cache.AbstractStringCacheStore; import run.halo.app.config.properties.HaloProperties; import run.halo.app.event.logger.LogEvent; import run.halo.app.exception.BadRequestException; @@ -85,7 +85,7 @@ public class AdminServiceImpl implements AdminService { private final MailService mailService; - private final StringCacheStore cacheStore; + private final AbstractStringCacheStore cacheStore; private final RestTemplate restTemplate; @@ -107,7 +107,7 @@ public class AdminServiceImpl implements AdminService { UserService userService, LinkService linkService, MailService mailService, - StringCacheStore cacheStore, + AbstractStringCacheStore cacheStore, RestTemplate restTemplate, HaloProperties haloProperties, ApplicationEventPublisher eventPublisher, diff --git a/src/main/java/run/halo/app/service/impl/CategoryServiceImpl.java b/src/main/java/run/halo/app/service/impl/CategoryServiceImpl.java index 089e4f1fc..d1282aafe 100644 --- a/src/main/java/run/halo/app/service/impl/CategoryServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/CategoryServiceImpl.java @@ -25,6 +25,8 @@ import java.util.LinkedList; import java.util.List; import java.util.stream.Collectors; +import static run.halo.app.model.support.HaloConst.URL_SEPARATOR; + /** * CategoryService implementation class. * @@ -130,9 +132,9 @@ public class CategoryServiceImpl extends AbstractCrudService fullPath.append(optionService.getBlogBaseUrl()); } - fullPath.append("/") + fullPath.append(URL_SEPARATOR) .append(optionService.getCategoriesPrefix()) - .append("/") + .append(URL_SEPARATOR) .append(child.getSlug()) .append(optionService.getPathSuffix()); @@ -216,9 +218,9 @@ public class CategoryServiceImpl extends AbstractCrudService fullPath.append(optionService.getBlogBaseUrl()); } - fullPath.append("/") + fullPath.append(URL_SEPARATOR) .append(optionService.getCategoriesPrefix()) - .append("/") + .append(URL_SEPARATOR) .append(category.getSlug()) .append(optionService.getPathSuffix()); diff --git a/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java b/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java index adb0ed538..8055f2cd1 100644 --- a/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java @@ -1,7 +1,7 @@ package run.halo.app.service.impl; -import cn.hutool.core.util.StrUtil; import com.qiniu.common.Zone; +import com.qiniu.storage.Region; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.context.ApplicationContext; @@ -15,7 +15,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; -import run.halo.app.cache.StringCacheStore; +import run.halo.app.cache.AbstractStringCacheStore; import run.halo.app.config.properties.HaloProperties; import run.halo.app.event.options.OptionUpdatedEvent; import run.halo.app.exception.MissingPropertyException; @@ -31,7 +31,6 @@ import run.halo.app.repository.OptionRepository; import run.halo.app.service.OptionService; import run.halo.app.service.base.AbstractCrudService; import run.halo.app.utils.DateUtils; -import run.halo.app.utils.HaloUtils; import run.halo.app.utils.ServiceUtils; import run.halo.app.utils.ValidationUtils; @@ -52,7 +51,7 @@ public class OptionServiceImpl extends AbstractCrudService impl private final OptionRepository optionRepository; private final ApplicationContext applicationContext; - private final StringCacheStore cacheStore; + private final AbstractStringCacheStore cacheStore; private final Map propertyEnumMap; private final ApplicationEventPublisher eventPublisher; private HaloProperties haloProperties; @@ -60,7 +59,7 @@ public class OptionServiceImpl extends AbstractCrudService impl public OptionServiceImpl(HaloProperties haloProperties, OptionRepository optionRepository, ApplicationContext applicationContext, - StringCacheStore cacheStore, + AbstractStringCacheStore cacheStore, ApplicationEventPublisher eventPublisher) { super(optionRepository); this.haloProperties = haloProperties; @@ -433,6 +432,36 @@ public class OptionServiceImpl extends AbstractCrudService impl }).orElseGet(Zone::autoZone); } + @Override + public Region getQiniuRegion() { + return getByProperty(QiniuOssProperties.OSS_ZONE).map(qiniuZone -> { + + Region region; + switch (qiniuZone.toString()) { + case "z0": + region = Region.region0(); + break; + case "z1": + region = Region.region1(); + break; + case "z2": + region = Region.region2(); + break; + case "na0": + region = Region.regionNa0(); + break; + case "as0": + region = Region.regionAs0(); + break; + default: + // Default is detecting zone automatically + region = Region.autoRegion(); + } + return region; + + }).orElseGet(Region::autoRegion); + } + @Override public Locale getLocale() { return getByProperty(BlogProperties.BLOG_LOCALE).map(localeStr -> { @@ -451,14 +480,10 @@ public class OptionServiceImpl extends AbstractCrudService impl String blogUrl = getByProperty(BlogProperties.BLOG_URL).orElse("").toString(); - if (StrUtil.isNotBlank(blogUrl)) { - blogUrl = StrUtil.removeSuffix(blogUrl, "/"); + if (StringUtils.isNotBlank(blogUrl)) { + blogUrl = StringUtils.removeEnd(blogUrl, "/"); } else { - if (haloProperties.isProductionEnv()) { - blogUrl = String.format("http://%s:%s", "127.0.0.1", serverPort); - } else { - blogUrl = String.format("http://%s:%s", HaloUtils.getMachineIP(), serverPort); - } + blogUrl = String.format("http://%s:%s", "127.0.0.1", serverPort); } return blogUrl; diff --git a/src/main/java/run/halo/app/service/impl/PostCategoryServiceImpl.java b/src/main/java/run/halo/app/service/impl/PostCategoryServiceImpl.java index 9acf7e6ca..48b7e16cd 100644 --- a/src/main/java/run/halo/app/service/impl/PostCategoryServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/PostCategoryServiceImpl.java @@ -24,6 +24,8 @@ import run.halo.app.utils.ServiceUtils; import java.util.*; import java.util.stream.Collectors; +import static run.halo.app.model.support.HaloConst.URL_SEPARATOR; + /** * Post category service implementation. * @@ -253,9 +255,9 @@ public class PostCategoryServiceImpl extends AbstractCrudService fullPath.append(optionService.getBlogBaseUrl()); } - fullPath.append("/"); + fullPath.append(URL_SEPARATOR); if (permalinkType.equals(PostPermalinkType.DEFAULT)) { fullPath.append(archivesPrefix) - .append("/") + .append(URL_SEPARATOR) .append(post.getSlug()) .append(pathSuffix); } else if (permalinkType.equals(PostPermalinkType.ID)) { @@ -137,18 +139,18 @@ public class PostCommentServiceImpl extends BaseCommentServiceImpl .append(post.getId()); } else if (permalinkType.equals(PostPermalinkType.DATE)) { fullPath.append(DateUtil.year(post.getCreateTime())) - .append("/") + .append(URL_SEPARATOR) .append(monthString) - .append("/") + .append(URL_SEPARATOR) .append(post.getSlug()) .append(pathSuffix); } else if (permalinkType.equals(PostPermalinkType.DAY)) { fullPath.append(DateUtil.year(post.getCreateTime())) - .append("/") + .append(URL_SEPARATOR) .append(monthString) - .append("/") + .append(URL_SEPARATOR) .append(dayString) - .append("/") + .append(URL_SEPARATOR) .append(post.getSlug()) .append(pathSuffix); } diff --git a/src/main/java/run/halo/app/service/impl/PostServiceImpl.java b/src/main/java/run/halo/app/service/impl/PostServiceImpl.java index 59a55f8a5..c8e9605a9 100644 --- a/src/main/java/run/halo/app/service/impl/PostServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/PostServiceImpl.java @@ -1,8 +1,6 @@ package run.halo.app.service.impl; import cn.hutool.core.date.DateUtil; -import cn.hutool.core.text.StrBuilder; -import cn.hutool.core.util.StrUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.context.ApplicationEventPublisher; @@ -46,6 +44,7 @@ import java.util.*; import java.util.stream.Collectors; import static org.springframework.data.domain.Sort.Direction.DESC; +import static run.halo.app.model.support.HaloConst.URL_SEPARATOR; /** * Post service implementation. @@ -383,11 +382,11 @@ public class PostServiceImpl extends BasePostServiceImpl implements PostSe post.setStatus(PostStatus.PUBLISHED); } - if (StrUtil.isEmpty(post.getTitle())) { + if (StringUtils.isEmpty(post.getTitle())) { post.setTitle(filename); } - if (StrUtil.isEmpty(post.getSlug())) { + if (StringUtils.isEmpty(post.getSlug())) { post.setSlug(SlugUtils.slug(post.getTitle())); } @@ -407,7 +406,7 @@ public class PostServiceImpl extends BasePostServiceImpl implements PostSe public String exportMarkdown(Post post) { Assert.notNull(post, "Post must not be null"); - StrBuilder content = new StrBuilder("---\n"); + StringBuilder content = new StringBuilder("---\n"); content.append("type: ").append("post").append("\n"); content.append("title: ").append(post.getTitle()).append("\n"); @@ -885,11 +884,11 @@ public class PostServiceImpl extends BasePostServiceImpl implements PostSe fullPath.append(optionService.getBlogBaseUrl()); } - fullPath.append("/"); + fullPath.append(URL_SEPARATOR); if (permalinkType.equals(PostPermalinkType.DEFAULT)) { fullPath.append(archivesPrefix) - .append("/") + .append(URL_SEPARATOR) .append(post.getSlug()) .append(pathSuffix); } else if (permalinkType.equals(PostPermalinkType.ID)) { @@ -897,18 +896,18 @@ public class PostServiceImpl extends BasePostServiceImpl implements PostSe .append(post.getId()); } else if (permalinkType.equals(PostPermalinkType.DATE)) { fullPath.append(DateUtil.year(post.getCreateTime())) - .append("/") + .append(URL_SEPARATOR) .append(monthString) - .append("/") + .append(URL_SEPARATOR) .append(post.getSlug()) .append(pathSuffix); } else if (permalinkType.equals(PostPermalinkType.DAY)) { fullPath.append(DateUtil.year(post.getCreateTime())) - .append("/") + .append(URL_SEPARATOR) .append(monthString) - .append("/") + .append(URL_SEPARATOR) .append(dayString) - .append("/") + .append(URL_SEPARATOR) .append(post.getSlug()) .append(pathSuffix); } diff --git a/src/main/java/run/halo/app/service/impl/PostTagServiceImpl.java b/src/main/java/run/halo/app/service/impl/PostTagServiceImpl.java index efd5e82b6..bb3160ab3 100644 --- a/src/main/java/run/halo/app/service/impl/PostTagServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/PostTagServiceImpl.java @@ -24,6 +24,8 @@ import run.halo.app.utils.ServiceUtils; import java.util.*; import java.util.stream.Collectors; +import static run.halo.app.model.support.HaloConst.URL_SEPARATOR; + /** * Post tag service implementation. * @@ -85,9 +87,9 @@ public class PostTagServiceImpl extends AbstractCrudService im fullPath.append(optionService.getBlogBaseUrl()); } - fullPath.append("/") + fullPath.append(URL_SEPARATOR) .append(optionService.getTagsPrefix()) - .append("/") + .append(URL_SEPARATOR) .append(tag.getSlug()) .append(optionService.getPathSuffix()); diff --git a/src/main/java/run/halo/app/service/impl/SheetCommentServiceImpl.java b/src/main/java/run/halo/app/service/impl/SheetCommentServiceImpl.java index 85b0083f1..251e858b5 100644 --- a/src/main/java/run/halo/app/service/impl/SheetCommentServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/SheetCommentServiceImpl.java @@ -25,6 +25,8 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +import static run.halo.app.model.support.HaloConst.URL_SEPARATOR; + /** * Sheet comment service implementation. * @@ -97,9 +99,9 @@ public class SheetCommentServiceImpl extends BaseCommentServiceImpl implements Shee public String exportMarkdown(Sheet sheet) { Assert.notNull(sheet, "Sheet must not be null"); - StrBuilder content = new StrBuilder("---\n"); + StringBuilder content = new StringBuilder("---\n"); content.append("type: ").append("sheet").append("\n"); content.append("title: ").append(sheet.getTitle()).append("\n"); @@ -342,9 +343,9 @@ public class SheetServiceImpl extends BasePostServiceImpl implements Shee fullPath.append(optionService.getBlogBaseUrl()); } - fullPath.append("/") + fullPath.append(URL_SEPARATOR) .append(optionService.getSheetPrefix()) - .append("/") + .append(URL_SEPARATOR) .append(sheet.getSlug()) .append(optionService.getPathSuffix()); diff --git a/src/main/java/run/halo/app/service/impl/TagServiceImpl.java b/src/main/java/run/halo/app/service/impl/TagServiceImpl.java index 40e02c705..802d022bc 100644 --- a/src/main/java/run/halo/app/service/impl/TagServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/TagServiceImpl.java @@ -18,6 +18,8 @@ import java.util.Collections; import java.util.List; import java.util.stream.Collectors; +import static run.halo.app.model.support.HaloConst.URL_SEPARATOR; + /** * TagService implementation class. * @@ -84,9 +86,9 @@ public class TagServiceImpl extends AbstractCrudService implements fullPath.append(optionService.getBlogBaseUrl()); } - fullPath.append("/") + fullPath.append(URL_SEPARATOR) .append(optionService.getTagsPrefix()) - .append("/") + .append(URL_SEPARATOR) .append(tag.getSlug()) .append(optionService.getPathSuffix()); diff --git a/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java b/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java index 25c142f61..5f00b4b3d 100644 --- a/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java @@ -22,7 +22,7 @@ import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.web.client.RestTemplate; import org.springframework.web.multipart.MultipartFile; -import run.halo.app.cache.StringCacheStore; +import run.halo.app.cache.AbstractStringCacheStore; import run.halo.app.config.properties.HaloProperties; import run.halo.app.event.theme.ThemeActivatedEvent; import run.halo.app.event.theme.ThemeUpdatedEvent; @@ -68,7 +68,7 @@ public class ThemeServiceImpl implements ThemeService { private final OptionService optionService; - private final StringCacheStore cacheStore; + private final AbstractStringCacheStore cacheStore; private final ThemeConfigResolver themeConfigResolver; @@ -90,7 +90,7 @@ public class ThemeServiceImpl implements ThemeService { public ThemeServiceImpl(HaloProperties haloProperties, OptionService optionService, - StringCacheStore cacheStore, + AbstractStringCacheStore cacheStore, ThemeConfigResolver themeConfigResolver, ThemePropertyResolver themePropertyResolver, RestTemplate restTemplate, diff --git a/src/main/java/run/halo/app/service/impl/UserServiceImpl.java b/src/main/java/run/halo/app/service/impl/UserServiceImpl.java index ce4febfbd..78133d6da 100644 --- a/src/main/java/run/halo/app/service/impl/UserServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/UserServiceImpl.java @@ -7,7 +7,7 @@ import org.springframework.lang.NonNull; import org.springframework.stereotype.Service; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; -import run.halo.app.cache.StringCacheStore; +import run.halo.app.cache.AbstractStringCacheStore; import run.halo.app.cache.lock.CacheLock; import run.halo.app.event.logger.LogEvent; import run.halo.app.event.user.UserUpdatedEvent; @@ -41,12 +41,12 @@ public class UserServiceImpl extends AbstractCrudService implemen private final UserRepository userRepository; - private final StringCacheStore stringCacheStore; + private final AbstractStringCacheStore stringCacheStore; private final ApplicationEventPublisher eventPublisher; public UserServiceImpl(UserRepository userRepository, - StringCacheStore stringCacheStore, + AbstractStringCacheStore stringCacheStore, ApplicationEventPublisher eventPublisher) { super(userRepository); this.userRepository = userRepository; diff --git a/src/main/java/run/halo/app/utils/HaloUtils.java b/src/main/java/run/halo/app/utils/HaloUtils.java index 25c0451d9..1ec534c59 100755 --- a/src/main/java/run/halo/app/utils/HaloUtils.java +++ b/src/main/java/run/halo/app/utils/HaloUtils.java @@ -6,6 +6,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; import org.springframework.util.Assert; +import run.halo.app.model.support.HaloConst; import java.net.InetAddress; import java.net.UnknownHostException; @@ -243,7 +244,7 @@ public class HaloUtils { public static String normalizeUrl(@NonNull String originalUrl) { Assert.hasText(originalUrl, "Original Url must not be blank"); - if (StringUtils.startsWithAny(originalUrl, "/", "https://", "http://") + if (StringUtils.startsWithAny(originalUrl, URL_SEPARATOR, HaloConst.PROTOCOL_HTTPS, HaloConst.PROTOCOL_HTTP) && !StringUtils.startsWith(originalUrl, "//")) { return originalUrl; } diff --git a/src/main/java/run/halo/app/utils/SlugUtils.java b/src/main/java/run/halo/app/utils/SlugUtils.java index 7164b9d5b..253b4d574 100644 --- a/src/main/java/run/halo/app/utils/SlugUtils.java +++ b/src/main/java/run/halo/app/utils/SlugUtils.java @@ -1,6 +1,6 @@ package run.halo.app.utils; -import cn.hutool.core.util.StrUtil; +import org.apache.commons.lang3.StringUtils; import org.springframework.lang.NonNull; import org.springframework.util.Assert; @@ -51,6 +51,6 @@ public class SlugUtils { replaceAll("[\\?\\\\/:|<>\\*\\[\\]\\(\\)\\$%\\{\\}@~\\.]", ""). replaceAll("\\s", "") .toLowerCase(Locale.ENGLISH); - return StrUtil.isNotEmpty(slug) ? slug : String.valueOf(System.currentTimeMillis()); + return StringUtils.isNotEmpty(slug) ? slug : String.valueOf(System.currentTimeMillis()); } } diff --git a/src/test/java/run/halo/app/cache/CacheStoreTest.java b/src/test/java/run/halo/app/cache/CacheStoreTest.java index 82b879ddc..cd8e1fe9a 100644 --- a/src/test/java/run/halo/app/cache/CacheStoreTest.java +++ b/src/test/java/run/halo/app/cache/CacheStoreTest.java @@ -16,7 +16,7 @@ import static org.junit.Assert.*; */ public class CacheStoreTest { - private StringCacheStore cacheStore = new InMemoryCacheStore(); + private AbstractStringCacheStore cacheStore = new InMemoryCacheStore(); @Test(expected = IllegalArgumentException.class) public void putNullValueTest() { diff --git a/src/test/java/run/halo/app/service/impl/OptionServiceImplTest.java b/src/test/java/run/halo/app/service/impl/OptionServiceImplTest.java index 765e120ff..05a13a121 100644 --- a/src/test/java/run/halo/app/service/impl/OptionServiceImplTest.java +++ b/src/test/java/run/halo/app/service/impl/OptionServiceImplTest.java @@ -6,7 +6,7 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import run.halo.app.cache.StringCacheStore; +import run.halo.app.cache.AbstractStringCacheStore; import run.halo.app.model.entity.Option; import run.halo.app.model.properties.QiniuOssProperties; import run.halo.app.repository.OptionRepository; @@ -35,7 +35,7 @@ public class OptionServiceImplTest { private OptionRepository optionRepository; @Mock - private StringCacheStore cacheStore; + private AbstractStringCacheStore cacheStore; @InjectMocks private OptionServiceImpl optionService;