style: code. (#692)

pull/695/head
Ryan Wang 2020-03-18 21:44:46 +08:00 committed by GitHub
parent f41c91b401
commit a70780c5df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
71 changed files with 535 additions and 463 deletions

View File

@ -17,7 +17,7 @@ import java.util.concurrent.TimeUnit;
* @author johnniang
*/
@Slf4j
public abstract class StringCacheStore extends AbstractCacheStore<String, String> {
public abstract class AbstractStringCacheStore extends AbstractCacheStore<String, String> {
public <T> void putAny(String key, T value) {
try {

View File

@ -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)

View File

@ -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");

View File

@ -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;
}

View File

@ -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();

View File

@ -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());

View File

@ -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
// }
//}

View File

@ -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);
});
}

View File

@ -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;

View File

@ -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;

View File

@ -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<StaticPageFile> 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<byte[]> httpEntity = new HttpEntity<>(bytes, headers);
ResponseEntity<Object> 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<StaticPageFile> 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<byte[]> httpEntity = new HttpEntity<>(bytes, headers);
//
// ResponseEntity<Object> responseEntity = httpsRestTemplate.postForEntity(String.format(DEPLOY_API, siteId), httpEntity, Object.class);
// }
//}

View File

@ -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<HttpTrace> listHttpTraces() {
// return traceService.listHttpTraces();
// }
//
//}

View File

@ -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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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());

View File

@ -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<BaseResponse> handleHaloException(HaloException e) {
@ExceptionHandler(AbstractHaloException.class)
public ResponseEntity<BaseResponse> handleHaloException(AbstractHaloException e) {
BaseResponse<Object> baseResponse = handleBaseException(e);
baseResponse.setStatus(e.getStatus().value());
baseResponse.setData(e.getErrorData());

View File

@ -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/");

View File

@ -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");

View File

@ -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.

View File

@ -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.

View File

@ -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;
}

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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)

View File

@ -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;
}
}

View File

@ -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)

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
/**

View File

@ -7,17 +7,64 @@ package run.halo.app.model.enums;
*/
public enum LogType implements ValueEnum<Integer> {
/**
* 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;

View File

@ -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;
/**

View File

@ -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

View File

@ -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.

View File

@ -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;

View File

@ -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.

View File

@ -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.

View File

@ -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

View File

@ -1,43 +0,0 @@
package run.halo.app.model.support;
import lombok.Data;
import java.util.Date;
/**
* <pre>
*
* </pre>
*
* @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;
}

View File

@ -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.
*/

View File

@ -1,40 +0,0 @@
package run.halo.app.model.support;
import lombok.Data;
/**
* <pre>
*
* </pre>
*
* @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;
}

View File

@ -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();

View File

@ -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,

View File

@ -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);

View File

@ -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);

View File

@ -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;
}

View File

@ -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;

View File

@ -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);

View File

@ -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;
}

View File

@ -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<Option, Integer> {
* @return qiniu zone
*/
@NonNull
@Deprecated
Zone getQnYunZone();
/**
* Get qiniu oss region.
*
* @return qiniu region
*/
@NonNull
Region getQiniuRegion();
/**
* Gets locale.
*

View File

@ -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,

View File

@ -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<Category, Integer>
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<Category, Integer>
fullPath.append(optionService.getBlogBaseUrl());
}
fullPath.append("/")
fullPath.append(URL_SEPARATOR)
.append(optionService.getCategoriesPrefix())
.append("/")
.append(URL_SEPARATOR)
.append(category.getSlug())
.append(optionService.getPathSuffix());

View File

@ -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<Option, Integer> impl
private final OptionRepository optionRepository;
private final ApplicationContext applicationContext;
private final StringCacheStore cacheStore;
private final AbstractStringCacheStore cacheStore;
private final Map<String, PropertyEnum> propertyEnumMap;
private final ApplicationEventPublisher eventPublisher;
private HaloProperties haloProperties;
@ -60,7 +59,7 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> 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<Option, Integer> 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<Option, Integer> 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);
}
}
return blogUrl;

View File

@ -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<PostCategory, I
fullPath.append(optionService.getBlogBaseUrl());
}
fullPath.append("/")
fullPath.append(URL_SEPARATOR)
.append(optionService.getCategoriesPrefix())
.append("/")
.append(URL_SEPARATOR)
.append(category.getSlug())
.append(optionService.getPathSuffix());

View File

@ -33,6 +33,8 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import static run.halo.app.model.support.HaloConst.URL_SEPARATOR;
/**
* PostCommentService implementation class
*
@ -125,11 +127,11 @@ public class PostCommentServiceImpl extends BaseCommentServiceImpl<PostComment>
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<PostComment>
.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);
}

View File

@ -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<Post> 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<Post> 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<Post> 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<Post> 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);
}

View File

@ -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<PostTag, Integer> im
fullPath.append(optionService.getBlogBaseUrl());
}
fullPath.append("/")
fullPath.append(URL_SEPARATOR)
.append(optionService.getTagsPrefix())
.append("/")
.append(URL_SEPARATOR)
.append(tag.getSlug())
.append(optionService.getPathSuffix());

View File

@ -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<SheetComment
fullPath.append(optionService.getBlogBaseUrl());
}
fullPath.append("/")
fullPath.append(URL_SEPARATOR)
.append(optionService.getSheetPrefix())
.append("/")
.append(URL_SEPARATOR)
.append(basePostMinimalDTO.getSlug())
.append(optionService.getPathSuffix());

View File

@ -1,6 +1,5 @@
package run.halo.app.service.impl;
import cn.hutool.core.text.StrBuilder;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.ApplicationEventPublisher;
@ -31,6 +30,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;
/**
* Sheet service implementation.
*
@ -173,7 +174,7 @@ public class SheetServiceImpl extends BasePostServiceImpl<Sheet> 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<Sheet> 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());

View File

@ -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<Tag, Integer> implements
fullPath.append(optionService.getBlogBaseUrl());
}
fullPath.append("/")
fullPath.append(URL_SEPARATOR)
.append(optionService.getTagsPrefix())
.append("/")
.append(URL_SEPARATOR)
.append(tag.getSlug())
.append(optionService.getPathSuffix());

View File

@ -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,

View File

@ -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<User, Integer> 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;

View File

@ -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;
}

View File

@ -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());
}
}

View File

@ -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() {

View File

@ -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;