mirror of https://github.com/halo-dev/halo
style: code. (#692)
parent
f41c91b401
commit
a70780c5df
|
@ -17,7 +17,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@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) {
|
public <T> void putAny(String key, T value) {
|
||||||
try {
|
try {
|
|
@ -17,7 +17,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class InMemoryCacheStore extends StringCacheStore {
|
public class InMemoryCacheStore extends AbstractStringCacheStore {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cleaner schedule period. (ms)
|
* Cleaner schedule period. (ms)
|
||||||
|
|
|
@ -22,7 +22,7 @@ import java.util.*;
|
||||||
* Create by Pencilso on 2020/1/9 7:20 下午
|
* Create by Pencilso on 2020/1/9 7:20 下午
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class LevelCacheStore extends StringCacheStore {
|
public class LevelCacheStore extends AbstractStringCacheStore {
|
||||||
/**
|
/**
|
||||||
* Cleaner schedule period. (ms)
|
* Cleaner schedule period. (ms)
|
||||||
*/
|
*/
|
||||||
|
@ -37,7 +37,9 @@ public class LevelCacheStore extends StringCacheStore {
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
if (LEVEL_DB != null) return;
|
if (LEVEL_DB != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
//work path
|
//work path
|
||||||
File folder = new File(haloProperties.getWorkDir() + ".leveldb");
|
File folder = new File(haloProperties.getWorkDir() + ".leveldb");
|
||||||
|
|
|
@ -9,7 +9,7 @@ import org.aspectj.lang.reflect.MethodSignature;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
import org.springframework.util.Assert;
|
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.FrequentAccessException;
|
||||||
import run.halo.app.exception.ServiceException;
|
import run.halo.app.exception.ServiceException;
|
||||||
import run.halo.app.utils.ServletUtils;
|
import run.halo.app.utils.ServletUtils;
|
||||||
|
@ -31,9 +31,9 @@ public class CacheLockInterceptor {
|
||||||
|
|
||||||
private final static String CACHE_LOCK_VALUE = "locked";
|
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;
|
this.cacheStore = cacheStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,9 @@ import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
||||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
import run.halo.app.cache.AbstractStringCacheStore;
|
||||||
import run.halo.app.cache.InMemoryCacheStore;
|
import run.halo.app.cache.InMemoryCacheStore;
|
||||||
import run.halo.app.cache.LevelCacheStore;
|
import run.halo.app.cache.LevelCacheStore;
|
||||||
import run.halo.app.cache.StringCacheStore;
|
|
||||||
import run.halo.app.config.properties.HaloProperties;
|
import run.halo.app.config.properties.HaloProperties;
|
||||||
import run.halo.app.utils.HttpClientUtils;
|
import run.halo.app.utils.HttpClientUtils;
|
||||||
|
|
||||||
|
@ -51,8 +51,8 @@ public class HaloConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnMissingBean
|
@ConditionalOnMissingBean
|
||||||
public StringCacheStore stringCacheStore() {
|
public AbstractStringCacheStore stringCacheStore() {
|
||||||
StringCacheStore stringCacheStore;
|
AbstractStringCacheStore stringCacheStore;
|
||||||
switch (haloProperties.getCache()) {
|
switch (haloProperties.getCache()) {
|
||||||
case "level":
|
case "level":
|
||||||
stringCacheStore = new LevelCacheStore();
|
stringCacheStore = new LevelCacheStore();
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class BackupController {
|
||||||
// Load file as resource
|
// Load file as resource
|
||||||
Resource backupResource = backupService.loadFileAsResource(haloProperties.getBackupDir(), fileName);
|
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 to determine file's content type
|
||||||
try {
|
try {
|
||||||
contentType = request.getServletContext().getMimeType(backupResource.getFile().getAbsolutePath());
|
contentType = request.getServletContext().getMimeType(backupResource.getFile().getAbsolutePath());
|
||||||
|
@ -119,7 +119,7 @@ public class BackupController {
|
||||||
// Load exported data as resource
|
// Load exported data as resource
|
||||||
Resource exportDataResource = backupService.loadFileAsResource(haloProperties.getDataExportDir(), fileName);
|
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 to determine file's content type
|
||||||
try {
|
try {
|
||||||
contentType = request.getServletContext().getMimeType(exportDataResource.getFile().getAbsolutePath());
|
contentType = request.getServletContext().getMimeType(exportDataResource.getFile().getAbsolutePath());
|
||||||
|
|
|
@ -1,30 +1,28 @@
|
||||||
package run.halo.app.controller.admin.api;
|
//package run.halo.app.controller.admin.api;
|
||||||
|
//
|
||||||
import io.swagger.annotations.ApiOperation;
|
//import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
//import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
//import run.halo.app.service.DataProcessService;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
//import run.halo.app.service.ThemeSettingService;
|
||||||
import run.halo.app.service.DataProcessService;
|
//
|
||||||
import run.halo.app.service.ThemeSettingService;
|
///**
|
||||||
|
// * @author ryanwang
|
||||||
/**
|
// * @date 2019-12-29
|
||||||
* @author ryanwang
|
// */
|
||||||
* @date 2019-12-29
|
//@RestController
|
||||||
*/
|
//@RequestMapping("/api/admin/data/process")
|
||||||
@RestController
|
//public class DataProcessController {
|
||||||
@RequestMapping("/api/admin/data/process")
|
//
|
||||||
public class DataProcessController {
|
// private final DataProcessService dataProcessService;
|
||||||
|
//
|
||||||
private final DataProcessService dataProcessService;
|
// private final ThemeSettingService themeSettingService;
|
||||||
|
//
|
||||||
private final ThemeSettingService themeSettingService;
|
// public DataProcessController(DataProcessService dataProcessService,
|
||||||
|
// ThemeSettingService themeSettingService) {
|
||||||
public DataProcessController(DataProcessService dataProcessService,
|
// this.dataProcessService = dataProcessService;
|
||||||
ThemeSettingService themeSettingService) {
|
// this.themeSettingService = themeSettingService;
|
||||||
this.dataProcessService = dataProcessService;
|
// }
|
||||||
this.themeSettingService = themeSettingService;
|
//
|
||||||
}
|
|
||||||
|
|
||||||
// @PutMapping("url/replace")
|
// @PutMapping("url/replace")
|
||||||
// @ApiOperation("Replace url in all table.")
|
// @ApiOperation("Replace url in all table.")
|
||||||
// public void replaceUrl(@RequestParam("oldUrl") String oldUrl,
|
// public void replaceUrl(@RequestParam("oldUrl") String oldUrl,
|
||||||
|
@ -37,16 +35,16 @@ public class DataProcessController {
|
||||||
// public void deleteInactivatedThemeSettings() {
|
// public void deleteInactivatedThemeSettings() {
|
||||||
// themeSettingService.deleteInactivated();
|
// themeSettingService.deleteInactivated();
|
||||||
// }
|
// }
|
||||||
|
//
|
||||||
@DeleteMapping("tags/unused")
|
// @DeleteMapping("tags/unused")
|
||||||
@ApiOperation("Delete unused tags")
|
// @ApiOperation("Delete unused tags")
|
||||||
public void deleteUnusedTags() {
|
// public void deleteUnusedTags() {
|
||||||
// TODO
|
// // TODO
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@DeleteMapping("categories/unused")
|
// @DeleteMapping("categories/unused")
|
||||||
@ApiOperation("Delete unused categories")
|
// @ApiOperation("Delete unused categories")
|
||||||
public void deleteUnusedCategories() {
|
// public void deleteUnusedCategories() {
|
||||||
// TODO
|
// // TODO
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package run.halo.app.controller.admin.api;
|
package run.halo.app.controller.admin.api;
|
||||||
|
|
||||||
import cn.hutool.core.text.StrBuilder;
|
|
||||||
import cn.hutool.crypto.SecureUtil;
|
import cn.hutool.crypto.SecureUtil;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
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.cache.lock.CacheLock;
|
||||||
import run.halo.app.event.logger.LogEvent;
|
import run.halo.app.event.logger.LogEvent;
|
||||||
import run.halo.app.exception.BadRequestException;
|
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.Category;
|
||||||
import run.halo.app.model.entity.PostComment;
|
import run.halo.app.model.entity.PostComment;
|
||||||
import run.halo.app.model.entity.User;
|
import run.halo.app.model.entity.User;
|
||||||
|
@ -159,15 +157,15 @@ public class InstallController {
|
||||||
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private BaseComment createDefaultComment(@Nullable PostDetailVO post) {
|
private void createDefaultComment(@Nullable PostDetailVO post) {
|
||||||
if (post == null) {
|
if (post == null) {
|
||||||
return null;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
long commentCount = postCommentService.count();
|
long commentCount = postCommentService.count();
|
||||||
|
|
||||||
if (commentCount > 0) {
|
if (commentCount > 0) {
|
||||||
return null;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PostComment comment = new PostComment();
|
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.setContent("欢迎使用 Halo,这是你的第一条评论,头像来自 [Gravatar](https://cn.gravatar.com),你也可以通过注册 [Gravatar](https://cn.gravatar.com) 来显示自己的头像。");
|
||||||
comment.setEmail("hi@halo.run");
|
comment.setEmail("hi@halo.run");
|
||||||
comment.setPostId(post.getId());
|
comment.setPostId(post.getId());
|
||||||
return postCommentService.create(comment);
|
postCommentService.create(comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -260,10 +258,9 @@ public class InstallController {
|
||||||
// Update user
|
// Update user
|
||||||
return userService.update(user);
|
return userService.update(user);
|
||||||
}).orElseGet(() -> {
|
}).orElseGet(() -> {
|
||||||
StrBuilder gravatar = new StrBuilder("//cn.gravatar.com/avatar/");
|
String gravatar = "//cn.gravatar.com/avatar/" + SecureUtil.md5(installParam.getEmail()) +
|
||||||
gravatar.append(SecureUtil.md5(installParam.getEmail()));
|
"?s=256&d=mm";
|
||||||
gravatar.append("?s=256&d=mm");
|
installParam.setAvatar(gravatar);
|
||||||
installParam.setAvatar(gravatar.toString());
|
|
||||||
return userService.createBy(installParam);
|
return userService.createBy(installParam);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.web.PageableDefault;
|
import org.springframework.data.web.PageableDefault;
|
||||||
import org.springframework.web.bind.annotation.*;
|
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.BasePostDetailDTO;
|
||||||
import run.halo.app.model.dto.post.BasePostMinimalDTO;
|
import run.halo.app.model.dto.post.BasePostMinimalDTO;
|
||||||
import run.halo.app.model.dto.post.BasePostSimpleDTO;
|
import run.halo.app.model.dto.post.BasePostSimpleDTO;
|
||||||
|
@ -43,12 +43,12 @@ public class PostController {
|
||||||
|
|
||||||
private final PostService postService;
|
private final PostService postService;
|
||||||
|
|
||||||
private final StringCacheStore cacheStore;
|
private final AbstractStringCacheStore cacheStore;
|
||||||
|
|
||||||
private final OptionService optionService;
|
private final OptionService optionService;
|
||||||
|
|
||||||
public PostController(PostService postService,
|
public PostController(PostService postService,
|
||||||
StringCacheStore cacheStore,
|
AbstractStringCacheStore cacheStore,
|
||||||
OptionService optionService) {
|
OptionService optionService) {
|
||||||
this.postService = postService;
|
this.postService = postService;
|
||||||
this.cacheStore = cacheStore;
|
this.cacheStore = cacheStore;
|
||||||
|
|
|
@ -6,7 +6,7 @@ import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.web.PageableDefault;
|
import org.springframework.data.web.PageableDefault;
|
||||||
import org.springframework.web.bind.annotation.*;
|
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.InternalSheetDTO;
|
||||||
import run.halo.app.model.dto.post.BasePostDetailDTO;
|
import run.halo.app.model.dto.post.BasePostDetailDTO;
|
||||||
import run.halo.app.model.dto.post.BasePostMinimalDTO;
|
import run.halo.app.model.dto.post.BasePostMinimalDTO;
|
||||||
|
@ -41,12 +41,12 @@ public class SheetController {
|
||||||
|
|
||||||
private final SheetService sheetService;
|
private final SheetService sheetService;
|
||||||
|
|
||||||
private final StringCacheStore cacheStore;
|
private final AbstractStringCacheStore cacheStore;
|
||||||
|
|
||||||
private final OptionService optionService;
|
private final OptionService optionService;
|
||||||
|
|
||||||
public SheetController(SheetService sheetService,
|
public SheetController(SheetService sheetService,
|
||||||
StringCacheStore cacheStore,
|
AbstractStringCacheStore cacheStore,
|
||||||
OptionService optionService) {
|
OptionService optionService) {
|
||||||
this.sheetService = sheetService;
|
this.sheetService = sheetService;
|
||||||
this.cacheStore = cacheStore;
|
this.cacheStore = cacheStore;
|
||||||
|
|
|
@ -1,92 +1,92 @@
|
||||||
package run.halo.app.controller.admin.api;
|
//package run.halo.app.controller.admin.api;
|
||||||
|
//
|
||||||
import cn.hutool.core.io.FileUtil;
|
//import cn.hutool.core.io.FileUtil;
|
||||||
import io.swagger.annotations.ApiOperation;
|
//import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.http.HttpEntity;
|
//import org.springframework.http.HttpEntity;
|
||||||
import org.springframework.http.HttpHeaders;
|
//import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.MediaType;
|
//import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.ResponseEntity;
|
//import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
//import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
//import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
//import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
//import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
//import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.client.RestTemplate;
|
//import org.springframework.web.client.RestTemplate;
|
||||||
import run.halo.app.model.properties.NetlifyStaticDeployProperties;
|
//import run.halo.app.model.properties.NetlifyStaticDeployProperties;
|
||||||
import run.halo.app.model.support.StaticPageFile;
|
//import run.halo.app.model.support.StaticPageFile;
|
||||||
import run.halo.app.service.OptionService;
|
//import run.halo.app.service.OptionService;
|
||||||
import run.halo.app.service.StaticPageService;
|
//import run.halo.app.service.StaticPageService;
|
||||||
|
//
|
||||||
import java.io.FileNotFoundException;
|
//import java.io.FileNotFoundException;
|
||||||
import java.nio.file.Path;
|
//import java.nio.file.Path;
|
||||||
import java.util.Collections;
|
//import java.util.Collections;
|
||||||
import java.util.List;
|
//import java.util.List;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* Static page controller.
|
// * Static page controller.
|
||||||
*
|
// *
|
||||||
* @author ryanwang
|
// * @author ryanwang
|
||||||
* @date 2019-12-25
|
// * @date 2019-12-25
|
||||||
*/
|
// */
|
||||||
@RestController
|
//@RestController
|
||||||
@RequestMapping("/api/admin/static_page")
|
//@RequestMapping("/api/admin/static_page")
|
||||||
public class StaticPageController {
|
//public class StaticPageController {
|
||||||
|
//
|
||||||
private final static String DEPLOY_API = "https://api.netlify.com/api/v1/sites/%s/deploys";
|
// private final static String DEPLOY_API = "https://api.netlify.com/api/v1/sites/%s/deploys";
|
||||||
|
//
|
||||||
private final OptionService optionService;
|
// private final OptionService optionService;
|
||||||
|
//
|
||||||
private final RestTemplate httpsRestTemplate;
|
// private final RestTemplate httpsRestTemplate;
|
||||||
|
//
|
||||||
private final StaticPageService staticPageService;
|
// private final StaticPageService staticPageService;
|
||||||
|
//
|
||||||
public StaticPageController(StaticPageService staticPageService,
|
// public StaticPageController(StaticPageService staticPageService,
|
||||||
OptionService optionService,
|
// OptionService optionService,
|
||||||
RestTemplate httpsRestTemplate) {
|
// RestTemplate httpsRestTemplate) {
|
||||||
this.staticPageService = staticPageService;
|
// this.staticPageService = staticPageService;
|
||||||
this.optionService = optionService;
|
// this.optionService = optionService;
|
||||||
this.httpsRestTemplate = httpsRestTemplate;
|
// this.httpsRestTemplate = httpsRestTemplate;
|
||||||
|
//
|
||||||
MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
|
// MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
|
||||||
mappingJackson2HttpMessageConverter.setSupportedMediaTypes(Collections.singletonList(MediaType.ALL));
|
// mappingJackson2HttpMessageConverter.setSupportedMediaTypes(Collections.singletonList(MediaType.ALL));
|
||||||
this.httpsRestTemplate.getMessageConverters().add(mappingJackson2HttpMessageConverter);
|
// this.httpsRestTemplate.getMessageConverters().add(mappingJackson2HttpMessageConverter);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@GetMapping
|
// @GetMapping
|
||||||
@ApiOperation("List static page files.")
|
// @ApiOperation("List static page files.")
|
||||||
public List<StaticPageFile> list() {
|
// public List<StaticPageFile> list() {
|
||||||
return staticPageService.listFile();
|
// return staticPageService.listFile();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@GetMapping("generate")
|
// @GetMapping("generate")
|
||||||
@ApiOperation("Generate static page files.")
|
// @ApiOperation("Generate static page files.")
|
||||||
public void generate() {
|
// public void generate() {
|
||||||
staticPageService.generate();
|
// staticPageService.generate();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@PostMapping("deploy")
|
// @PostMapping("deploy")
|
||||||
@ApiOperation("Deploy static page to remove platform")
|
// @ApiOperation("Deploy static page to remove platform")
|
||||||
public void deploy() {
|
// public void deploy() {
|
||||||
staticPageService.deploy();
|
// staticPageService.deploy();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@GetMapping("netlify")
|
// @GetMapping("netlify")
|
||||||
public void testNetlify() throws FileNotFoundException {
|
// public void testNetlify() throws FileNotFoundException {
|
||||||
String domain = optionService.getByPropertyOfNonNull(NetlifyStaticDeployProperties.NETLIFY_DOMAIN).toString();
|
// String domain = optionService.getByPropertyOfNonNull(NetlifyStaticDeployProperties.NETLIFY_DOMAIN).toString();
|
||||||
String siteId = optionService.getByPropertyOfNonNull(NetlifyStaticDeployProperties.NETLIFY_SITE_ID).toString();
|
// String siteId = optionService.getByPropertyOfNonNull(NetlifyStaticDeployProperties.NETLIFY_SITE_ID).toString();
|
||||||
String token = optionService.getByPropertyOfNonNull(NetlifyStaticDeployProperties.NETLIFY_TOKEN).toString();
|
// String token = optionService.getByPropertyOfNonNull(NetlifyStaticDeployProperties.NETLIFY_TOKEN).toString();
|
||||||
|
//
|
||||||
HttpHeaders headers = new HttpHeaders();
|
// HttpHeaders headers = new HttpHeaders();
|
||||||
|
//
|
||||||
headers.set("Content-Type", "application/zip");
|
// headers.set("Content-Type", "application/zip");
|
||||||
headers.set(HttpHeaders.AUTHORIZATION, "Bearer " + token);
|
// headers.set(HttpHeaders.AUTHORIZATION, "Bearer " + token);
|
||||||
|
//
|
||||||
Path path = staticPageService.zipStaticPagesDirectory();
|
// Path path = staticPageService.zipStaticPagesDirectory();
|
||||||
|
//
|
||||||
byte[] bytes = FileUtil.readBytes(path.toFile());
|
// byte[] bytes = FileUtil.readBytes(path.toFile());
|
||||||
|
//
|
||||||
HttpEntity<byte[]> httpEntity = new HttpEntity<>(bytes, headers);
|
// HttpEntity<byte[]> httpEntity = new HttpEntity<>(bytes, headers);
|
||||||
|
//
|
||||||
ResponseEntity<Object> responseEntity = httpsRestTemplate.postForEntity(String.format(DEPLOY_API, siteId), httpEntity, Object.class);
|
// ResponseEntity<Object> responseEntity = httpsRestTemplate.postForEntity(String.format(DEPLOY_API, siteId), httpEntity, Object.class);
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
|
@ -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();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//}
|
|
|
@ -5,7 +5,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.*;
|
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.cache.lock.CacheLock;
|
||||||
import run.halo.app.controller.content.model.*;
|
import run.halo.app.controller.content.model.*;
|
||||||
import run.halo.app.exception.NotFoundException;
|
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.OptionService;
|
||||||
import run.halo.app.service.PostService;
|
import run.halo.app.service.PostService;
|
||||||
import run.halo.app.service.SheetService;
|
import run.halo.app.service.SheetService;
|
||||||
import run.halo.app.service.ThemeService;
|
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
@ -53,9 +52,7 @@ public class ContentContentController {
|
||||||
|
|
||||||
private final SheetService sheetService;
|
private final SheetService sheetService;
|
||||||
|
|
||||||
private final ThemeService themeService;
|
private final AbstractStringCacheStore cacheStore;
|
||||||
|
|
||||||
private final StringCacheStore cacheStore;
|
|
||||||
|
|
||||||
public ContentContentController(PostModel postModel,
|
public ContentContentController(PostModel postModel,
|
||||||
SheetModel sheetModel,
|
SheetModel sheetModel,
|
||||||
|
@ -67,8 +64,7 @@ public class ContentContentController {
|
||||||
OptionService optionService,
|
OptionService optionService,
|
||||||
PostService postService,
|
PostService postService,
|
||||||
SheetService sheetService,
|
SheetService sheetService,
|
||||||
ThemeService themeService,
|
AbstractStringCacheStore cacheStore) {
|
||||||
StringCacheStore cacheStore) {
|
|
||||||
this.postModel = postModel;
|
this.postModel = postModel;
|
||||||
this.sheetModel = sheetModel;
|
this.sheetModel = sheetModel;
|
||||||
this.categoryModel = categoryModel;
|
this.categoryModel = categoryModel;
|
||||||
|
@ -79,7 +75,6 @@ public class ContentContentController {
|
||||||
this.optionService = optionService;
|
this.optionService = optionService;
|
||||||
this.postService = postService;
|
this.postService = postService;
|
||||||
this.sheetService = sheetService;
|
this.sheetService = sheetService;
|
||||||
this.themeService = themeService;
|
|
||||||
this.cacheStore = cacheStore;
|
this.cacheStore = cacheStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.ui.Model;
|
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.exception.ForbiddenException;
|
||||||
import run.halo.app.model.entity.Category;
|
import run.halo.app.model.entity.Category;
|
||||||
import run.halo.app.model.entity.Post;
|
import run.halo.app.model.entity.Post;
|
||||||
|
@ -50,7 +50,7 @@ public class PostModel {
|
||||||
|
|
||||||
private final OptionService optionService;
|
private final OptionService optionService;
|
||||||
|
|
||||||
private final StringCacheStore cacheStore;
|
private final AbstractStringCacheStore cacheStore;
|
||||||
|
|
||||||
public PostModel(PostService postService,
|
public PostModel(PostService postService,
|
||||||
ThemeService themeService,
|
ThemeService themeService,
|
||||||
|
@ -60,7 +60,7 @@ public class PostModel {
|
||||||
PostTagService postTagService,
|
PostTagService postTagService,
|
||||||
TagService tagService,
|
TagService tagService,
|
||||||
OptionService optionService,
|
OptionService optionService,
|
||||||
StringCacheStore cacheStore) {
|
AbstractStringCacheStore cacheStore) {
|
||||||
this.postService = postService;
|
this.postService = postService;
|
||||||
this.themeService = themeService;
|
this.themeService = themeService;
|
||||||
this.postCategoryService = postCategoryService;
|
this.postCategoryService = postCategoryService;
|
||||||
|
|
|
@ -3,7 +3,7 @@ package run.halo.app.controller.content.model;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.ui.Model;
|
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.exception.ForbiddenException;
|
||||||
import run.halo.app.model.entity.Sheet;
|
import run.halo.app.model.entity.Sheet;
|
||||||
import run.halo.app.model.entity.SheetMeta;
|
import run.halo.app.model.entity.SheetMeta;
|
||||||
|
@ -32,7 +32,7 @@ public class SheetModel {
|
||||||
|
|
||||||
private final SheetMetaService sheetMetaService;
|
private final SheetMetaService sheetMetaService;
|
||||||
|
|
||||||
private final StringCacheStore cacheStore;
|
private final AbstractStringCacheStore cacheStore;
|
||||||
|
|
||||||
private final ThemeService themeService;
|
private final ThemeService themeService;
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ public class SheetModel {
|
||||||
|
|
||||||
public SheetModel(SheetService sheetService,
|
public SheetModel(SheetService sheetService,
|
||||||
SheetMetaService sheetMetaService,
|
SheetMetaService sheetMetaService,
|
||||||
StringCacheStore cacheStore,
|
AbstractStringCacheStore cacheStore,
|
||||||
ThemeService themeService,
|
ThemeService themeService,
|
||||||
OptionService optionService) {
|
OptionService optionService) {
|
||||||
this.sheetService = sheetService;
|
this.sheetService = sheetService;
|
||||||
|
|
|
@ -15,7 +15,7 @@ import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.util.NestedServletException;
|
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.exception.NotFoundException;
|
||||||
import run.halo.app.service.OptionService;
|
import run.halo.app.service.OptionService;
|
||||||
import run.halo.app.service.ThemeService;
|
import run.halo.app.service.ThemeService;
|
||||||
|
@ -170,8 +170,8 @@ public class CommonController extends AbstractErrorController {
|
||||||
|
|
||||||
if (throwable instanceof NestedServletException) {
|
if (throwable instanceof NestedServletException) {
|
||||||
Throwable rootCause = ((NestedServletException) throwable).getRootCause();
|
Throwable rootCause = ((NestedServletException) throwable).getRootCause();
|
||||||
if (rootCause instanceof HaloException) {
|
if (rootCause instanceof AbstractHaloException) {
|
||||||
HaloException haloException = (HaloException) rootCause;
|
AbstractHaloException haloException = (AbstractHaloException) rootCause;
|
||||||
request.setAttribute("javax.servlet.error.status_code", haloException.getStatus().value());
|
request.setAttribute("javax.servlet.error.status_code", haloException.getStatus().value());
|
||||||
request.setAttribute("javax.servlet.error.exception", rootCause);
|
request.setAttribute("javax.servlet.error.exception", rootCause);
|
||||||
request.setAttribute("javax.servlet.error.message", haloException.getMessage());
|
request.setAttribute("javax.servlet.error.message", haloException.getMessage());
|
||||||
|
|
|
@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
import org.springframework.web.servlet.NoHandlerFoundException;
|
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.model.support.BaseResponse;
|
||||||
import run.halo.app.utils.ExceptionUtils;
|
import run.halo.app.utils.ExceptionUtils;
|
||||||
import run.halo.app.utils.ValidationUtils;
|
import run.halo.app.utils.ValidationUtils;
|
||||||
|
@ -106,8 +106,8 @@ public class ControllerExceptionHandler {
|
||||||
return baseResponse;
|
return baseResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler(HaloException.class)
|
@ExceptionHandler(AbstractHaloException.class)
|
||||||
public ResponseEntity<BaseResponse> handleHaloException(HaloException e) {
|
public ResponseEntity<BaseResponse> handleHaloException(AbstractHaloException e) {
|
||||||
BaseResponse<Object> baseResponse = handleBaseException(e);
|
BaseResponse<Object> baseResponse = handleBaseException(e);
|
||||||
baseResponse.setStatus(e.getStatus().value());
|
baseResponse.setStatus(e.getStatus().value());
|
||||||
baseResponse.setData(e.getErrorData());
|
baseResponse.setData(e.getErrorData());
|
||||||
|
|
|
@ -14,6 +14,8 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static run.halo.app.model.support.HaloConst.URL_SEPARATOR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ryanwang
|
* @author ryanwang
|
||||||
* @date 2020-03-07
|
* @date 2020-03-07
|
||||||
|
@ -71,7 +73,7 @@ public class PaginationTagDirective implements TemplateDirectiveModel {
|
||||||
.append(pathSuffix);
|
.append(pathSuffix);
|
||||||
|
|
||||||
if (page == 1) {
|
if (page == 1) {
|
||||||
prevPageFullPath.append("/");
|
prevPageFullPath.append(URL_SEPARATOR);
|
||||||
} else {
|
} else {
|
||||||
prevPageFullPath.append("/page/")
|
prevPageFullPath.append("/page/")
|
||||||
.append(page)
|
.append(page)
|
||||||
|
@ -90,9 +92,9 @@ public class PaginationTagDirective implements TemplateDirectiveModel {
|
||||||
break;
|
break;
|
||||||
case "archives":
|
case "archives":
|
||||||
|
|
||||||
nextPageFullPath.append("/")
|
nextPageFullPath.append(URL_SEPARATOR)
|
||||||
.append(optionService.getArchivesPrefix());
|
.append(optionService.getArchivesPrefix());
|
||||||
prevPageFullPath.append("/")
|
prevPageFullPath.append(URL_SEPARATOR)
|
||||||
.append(optionService.getArchivesPrefix());
|
.append(optionService.getArchivesPrefix());
|
||||||
|
|
||||||
nextPageFullPath.append("/page/")
|
nextPageFullPath.append("/page/")
|
||||||
|
@ -108,7 +110,7 @@ public class PaginationTagDirective implements TemplateDirectiveModel {
|
||||||
.append(pathSuffix);
|
.append(pathSuffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
fullPath.append("/")
|
fullPath.append(URL_SEPARATOR)
|
||||||
.append(optionService.getArchivesPrefix());
|
.append(optionService.getArchivesPrefix());
|
||||||
|
|
||||||
fullPath.append("/page/");
|
fullPath.append("/page/");
|
||||||
|
@ -124,9 +126,9 @@ public class PaginationTagDirective implements TemplateDirectiveModel {
|
||||||
case "search":
|
case "search":
|
||||||
String keyword = params.get("keyword").toString();
|
String keyword = params.get("keyword").toString();
|
||||||
|
|
||||||
nextPageFullPath.append("/")
|
nextPageFullPath.append(URL_SEPARATOR)
|
||||||
.append("search");
|
.append("search");
|
||||||
prevPageFullPath.append("/")
|
prevPageFullPath.append(URL_SEPARATOR)
|
||||||
.append("search");
|
.append("search");
|
||||||
|
|
||||||
nextPageFullPath.append("/page/")
|
nextPageFullPath.append("/page/")
|
||||||
|
@ -147,7 +149,7 @@ public class PaginationTagDirective implements TemplateDirectiveModel {
|
||||||
.append(keyword);
|
.append(keyword);
|
||||||
}
|
}
|
||||||
|
|
||||||
fullPath.append("/")
|
fullPath.append(URL_SEPARATOR)
|
||||||
.append("search");
|
.append("search");
|
||||||
|
|
||||||
fullPath.append("/page/");
|
fullPath.append("/page/");
|
||||||
|
@ -163,13 +165,13 @@ public class PaginationTagDirective implements TemplateDirectiveModel {
|
||||||
case "tagPosts":
|
case "tagPosts":
|
||||||
String tagSlug = params.get("slug").toString();
|
String tagSlug = params.get("slug").toString();
|
||||||
|
|
||||||
nextPageFullPath.append("/")
|
nextPageFullPath.append(URL_SEPARATOR)
|
||||||
.append(optionService.getTagsPrefix())
|
.append(optionService.getTagsPrefix())
|
||||||
.append("/")
|
.append(URL_SEPARATOR)
|
||||||
.append(tagSlug);
|
.append(tagSlug);
|
||||||
prevPageFullPath.append("/")
|
prevPageFullPath.append(URL_SEPARATOR)
|
||||||
.append(optionService.getTagsPrefix())
|
.append(optionService.getTagsPrefix())
|
||||||
.append("/")
|
.append(URL_SEPARATOR)
|
||||||
.append(tagSlug);
|
.append(tagSlug);
|
||||||
|
|
||||||
nextPageFullPath.append("/page/")
|
nextPageFullPath.append("/page/")
|
||||||
|
@ -184,9 +186,9 @@ public class PaginationTagDirective implements TemplateDirectiveModel {
|
||||||
.append(pathSuffix);
|
.append(pathSuffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
fullPath.append("/")
|
fullPath.append(URL_SEPARATOR)
|
||||||
.append(optionService.getTagsPrefix())
|
.append(optionService.getTagsPrefix())
|
||||||
.append("/")
|
.append(URL_SEPARATOR)
|
||||||
.append(tagSlug);
|
.append(tagSlug);
|
||||||
|
|
||||||
fullPath.append("/page/");
|
fullPath.append("/page/");
|
||||||
|
@ -202,13 +204,13 @@ public class PaginationTagDirective implements TemplateDirectiveModel {
|
||||||
case "categoryPosts":
|
case "categoryPosts":
|
||||||
String categorySlug = params.get("slug").toString();
|
String categorySlug = params.get("slug").toString();
|
||||||
|
|
||||||
nextPageFullPath.append("/")
|
nextPageFullPath.append(URL_SEPARATOR)
|
||||||
.append(optionService.getCategoriesPrefix())
|
.append(optionService.getCategoriesPrefix())
|
||||||
.append("/")
|
.append(URL_SEPARATOR)
|
||||||
.append(categorySlug);
|
.append(categorySlug);
|
||||||
prevPageFullPath.append("/")
|
prevPageFullPath.append(URL_SEPARATOR)
|
||||||
.append(optionService.getCategoriesPrefix())
|
.append(optionService.getCategoriesPrefix())
|
||||||
.append("/")
|
.append(URL_SEPARATOR)
|
||||||
.append(categorySlug);
|
.append(categorySlug);
|
||||||
|
|
||||||
nextPageFullPath.append("/page/")
|
nextPageFullPath.append("/page/")
|
||||||
|
@ -223,9 +225,9 @@ public class PaginationTagDirective implements TemplateDirectiveModel {
|
||||||
.append(pathSuffix);
|
.append(pathSuffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
fullPath.append("/")
|
fullPath.append(URL_SEPARATOR)
|
||||||
.append(optionService.getCategoriesPrefix())
|
.append(optionService.getCategoriesPrefix())
|
||||||
.append("/")
|
.append(URL_SEPARATOR)
|
||||||
.append(categorySlug);
|
.append(categorySlug);
|
||||||
|
|
||||||
fullPath.append("/page/");
|
fullPath.append("/page/");
|
||||||
|
@ -240,9 +242,9 @@ public class PaginationTagDirective implements TemplateDirectiveModel {
|
||||||
break;
|
break;
|
||||||
case "photos":
|
case "photos":
|
||||||
|
|
||||||
nextPageFullPath.append("/")
|
nextPageFullPath.append(URL_SEPARATOR)
|
||||||
.append(optionService.getPhotosPrefix());
|
.append(optionService.getPhotosPrefix());
|
||||||
prevPageFullPath.append("/")
|
prevPageFullPath.append(URL_SEPARATOR)
|
||||||
.append(optionService.getPhotosPrefix());
|
.append(optionService.getPhotosPrefix());
|
||||||
|
|
||||||
nextPageFullPath.append("/page/")
|
nextPageFullPath.append("/page/")
|
||||||
|
@ -257,7 +259,7 @@ public class PaginationTagDirective implements TemplateDirectiveModel {
|
||||||
.append(pathSuffix);
|
.append(pathSuffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
fullPath.append("/")
|
fullPath.append(URL_SEPARATOR)
|
||||||
.append(optionService.getPhotosPrefix());
|
.append(optionService.getPhotosPrefix());
|
||||||
|
|
||||||
fullPath.append("/page/");
|
fullPath.append("/page/");
|
||||||
|
@ -272,9 +274,9 @@ public class PaginationTagDirective implements TemplateDirectiveModel {
|
||||||
break;
|
break;
|
||||||
case "journals":
|
case "journals":
|
||||||
|
|
||||||
nextPageFullPath.append("/")
|
nextPageFullPath.append(URL_SEPARATOR)
|
||||||
.append(optionService.getJournalsPrefix());
|
.append(optionService.getJournalsPrefix());
|
||||||
prevPageFullPath.append("/")
|
prevPageFullPath.append(URL_SEPARATOR)
|
||||||
.append(optionService.getJournalsPrefix());
|
.append(optionService.getJournalsPrefix());
|
||||||
|
|
||||||
nextPageFullPath.append("/page/")
|
nextPageFullPath.append("/page/")
|
||||||
|
@ -289,7 +291,7 @@ public class PaginationTagDirective implements TemplateDirectiveModel {
|
||||||
.append(pathSuffix);
|
.append(pathSuffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
fullPath.append("/")
|
fullPath.append(URL_SEPARATOR)
|
||||||
.append(optionService.getJournalsPrefix());
|
.append(optionService.getJournalsPrefix());
|
||||||
|
|
||||||
fullPath.append("/page/");
|
fullPath.append("/page/");
|
||||||
|
|
|
@ -10,7 +10,7 @@ import org.springframework.util.Assert;
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
* @date 19-4-23
|
* @date 19-4-23
|
||||||
*/
|
*/
|
||||||
public abstract class CommentBaseEvent extends ApplicationEvent {
|
public abstract class AbstractCommentBaseEvent extends ApplicationEvent {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PostComment id.
|
* 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 source the object on which the event initially occurred (never {@code null})
|
||||||
* @param commentId comment id
|
* @param commentId comment id
|
||||||
*/
|
*/
|
||||||
public CommentBaseEvent(Object source, @NonNull Long commentId) {
|
public AbstractCommentBaseEvent(Object source, @NonNull Long commentId) {
|
||||||
super(source);
|
super(source);
|
||||||
|
|
||||||
Assert.notNull(commentId, "PostComment id must not be null");
|
Assert.notNull(commentId, "PostComment id must not be null");
|
|
@ -8,7 +8,7 @@ import org.springframework.lang.NonNull;
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
* @date 19-4-23
|
* @date 19-4-23
|
||||||
*/
|
*/
|
||||||
public class CommentNewEvent extends CommentBaseEvent {
|
public class CommentNewEvent extends AbstractCommentBaseEvent {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new ApplicationEvent.
|
* Create a new ApplicationEvent.
|
||||||
|
|
|
@ -8,7 +8,7 @@ import org.springframework.lang.NonNull;
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
* @date 19-4-23
|
* @date 19-4-23
|
||||||
*/
|
*/
|
||||||
public class CommentReplyEvent extends CommentBaseEvent {
|
public class CommentReplyEvent extends AbstractCommentBaseEvent {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new ApplicationEvent.
|
* Create a new ApplicationEvent.
|
||||||
|
|
|
@ -8,22 +8,29 @@ import org.springframework.lang.Nullable;
|
||||||
* Base exception of the project.
|
* Base exception of the project.
|
||||||
*
|
*
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
|
* @author ryan0up
|
||||||
|
* @date 2019-03-15
|
||||||
*/
|
*/
|
||||||
public abstract class HaloException extends RuntimeException {
|
public abstract class AbstractHaloException extends RuntimeException {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Error errorData.
|
* Error errorData.
|
||||||
*/
|
*/
|
||||||
private Object errorData;
|
private Object errorData;
|
||||||
|
|
||||||
public HaloException(String message) {
|
public AbstractHaloException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HaloException(String message, Throwable cause) {
|
public AbstractHaloException(String message, Throwable cause) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Http status code
|
||||||
|
*
|
||||||
|
* @return {@link HttpStatus}
|
||||||
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public abstract HttpStatus getStatus();
|
public abstract HttpStatus getStatus();
|
||||||
|
|
||||||
|
@ -39,7 +46,7 @@ public abstract class HaloException extends RuntimeException {
|
||||||
* @return current exception.
|
* @return current exception.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public HaloException setErrorData(@Nullable Object errorData) {
|
public AbstractHaloException setErrorData(@Nullable Object errorData) {
|
||||||
this.errorData = errorData;
|
this.errorData = errorData;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
|
@ -7,7 +7,7 @@ import org.springframework.http.HttpStatus;
|
||||||
*
|
*
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
*/
|
*/
|
||||||
public class AuthenticationException extends HaloException {
|
public class AuthenticationException extends AbstractHaloException {
|
||||||
|
|
||||||
public AuthenticationException(String message) {
|
public AuthenticationException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
|
|
|
@ -7,7 +7,7 @@ import org.springframework.http.HttpStatus;
|
||||||
*
|
*
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
*/
|
*/
|
||||||
public class BadRequestException extends HaloException {
|
public class BadRequestException extends AbstractHaloException {
|
||||||
|
|
||||||
public BadRequestException(String message) {
|
public BadRequestException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
|
|
|
@ -7,7 +7,7 @@ import org.springframework.http.HttpStatus;
|
||||||
*
|
*
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
*/
|
*/
|
||||||
public class BeanUtilsException extends HaloException {
|
public class BeanUtilsException extends AbstractHaloException {
|
||||||
|
|
||||||
public BeanUtilsException(String message) {
|
public BeanUtilsException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
|
|
|
@ -7,7 +7,7 @@ import org.springframework.http.HttpStatus;
|
||||||
*
|
*
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
*/
|
*/
|
||||||
public class ForbiddenException extends HaloException {
|
public class ForbiddenException extends AbstractHaloException {
|
||||||
|
|
||||||
public ForbiddenException(String message) {
|
public ForbiddenException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
|
|
|
@ -7,7 +7,7 @@ import org.springframework.http.HttpStatus;
|
||||||
*
|
*
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
*/
|
*/
|
||||||
public class NotFoundException extends HaloException {
|
public class NotFoundException extends AbstractHaloException {
|
||||||
|
|
||||||
public NotFoundException(String message) {
|
public NotFoundException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
|
|
|
@ -7,7 +7,7 @@ import org.springframework.http.HttpStatus;
|
||||||
*
|
*
|
||||||
* @author johnniang
|
* @author johnniang
|
||||||
*/
|
*/
|
||||||
public class ServiceException extends HaloException {
|
public class ServiceException extends AbstractHaloException {
|
||||||
|
|
||||||
public ServiceException(String message) {
|
public ServiceException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
|
|
|
@ -21,6 +21,8 @@ import run.halo.app.utils.ImageUtils;
|
||||||
import javax.imageio.ImageReader;
|
import javax.imageio.ImageReader;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import static run.halo.app.model.support.HaloConst.URL_SEPARATOR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ali oss file handler.
|
* Ali oss file handler.
|
||||||
*
|
*
|
||||||
|
@ -60,12 +62,12 @@ public class AliOssFileHandler implements FileHandler {
|
||||||
|
|
||||||
if (StringUtils.isNotEmpty(domain)) {
|
if (StringUtils.isNotEmpty(domain)) {
|
||||||
basePath.append(domain)
|
basePath.append(domain)
|
||||||
.append("/");
|
.append(URL_SEPARATOR);
|
||||||
} else {
|
} else {
|
||||||
basePath.append(bucketName)
|
basePath.append(bucketName)
|
||||||
.append(".")
|
.append(".")
|
||||||
.append(endPoint)
|
.append(endPoint)
|
||||||
.append("/");
|
.append(URL_SEPARATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -76,7 +78,7 @@ public class AliOssFileHandler implements FileHandler {
|
||||||
|
|
||||||
if (StringUtils.isNotEmpty(source)) {
|
if (StringUtils.isNotEmpty(source)) {
|
||||||
upFilePath.append(source)
|
upFilePath.append(source)
|
||||||
.append("/");
|
.append(URL_SEPARATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
upFilePath.append(basename)
|
upFilePath.append(basename)
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
package run.halo.app.handler.file;
|
package run.halo.app.handler.file;
|
||||||
|
|
||||||
import com.qiniu.common.QiniuException;
|
import com.qiniu.common.QiniuException;
|
||||||
import com.qiniu.common.Zone;
|
|
||||||
import com.qiniu.http.Response;
|
import com.qiniu.http.Response;
|
||||||
import com.qiniu.storage.BucketManager;
|
import com.qiniu.storage.BucketManager;
|
||||||
import com.qiniu.storage.Configuration;
|
import com.qiniu.storage.Configuration;
|
||||||
|
import com.qiniu.storage.Region;
|
||||||
import com.qiniu.storage.UploadManager;
|
import com.qiniu.storage.UploadManager;
|
||||||
import com.qiniu.storage.persistent.FileRecorder;
|
import com.qiniu.storage.persistent.FileRecorder;
|
||||||
import com.qiniu.util.Auth;
|
import com.qiniu.util.Auth;
|
||||||
import com.qiniu.util.StringMap;
|
import com.qiniu.util.StringMap;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.http.MediaType;
|
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.exception.FileOperationException;
|
||||||
import run.halo.app.model.enums.AttachmentType;
|
import run.halo.app.model.enums.AttachmentType;
|
||||||
import run.halo.app.model.properties.QiniuOssProperties;
|
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.model.support.UploadResult;
|
||||||
import run.halo.app.service.OptionService;
|
import run.halo.app.service.OptionService;
|
||||||
import run.halo.app.utils.FilenameUtils;
|
import run.halo.app.utils.FilenameUtils;
|
||||||
|
@ -31,6 +32,7 @@ import java.nio.file.Paths;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import static run.halo.app.handler.file.FileHandler.isImageType;
|
import static run.halo.app.handler.file.FileHandler.isImageType;
|
||||||
|
import static run.halo.app.model.support.HaloConst.URL_SEPARATOR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Qiniu oss file handler.
|
* Qiniu oss file handler.
|
||||||
|
@ -53,8 +55,8 @@ public class QiniuOssFileHandler implements FileHandler {
|
||||||
public UploadResult upload(MultipartFile file) {
|
public UploadResult upload(MultipartFile file) {
|
||||||
Assert.notNull(file, "Multipart file must not be null");
|
Assert.notNull(file, "Multipart file must not be null");
|
||||||
|
|
||||||
// Get all config
|
Region region = optionService.getQiniuRegion();
|
||||||
Zone zone = optionService.getQnYunZone();
|
|
||||||
String accessKey = optionService.getByPropertyOfNonNull(QiniuOssProperties.OSS_ACCESS_KEY).toString();
|
String accessKey = optionService.getByPropertyOfNonNull(QiniuOssProperties.OSS_ACCESS_KEY).toString();
|
||||||
String secretKey = optionService.getByPropertyOfNonNull(QiniuOssProperties.OSS_SECRET_KEY).toString();
|
String secretKey = optionService.getByPropertyOfNonNull(QiniuOssProperties.OSS_SECRET_KEY).toString();
|
||||||
String bucket = optionService.getByPropertyOfNonNull(QiniuOssProperties.OSS_BUCKET).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, "");
|
String thumbnailStyleRule = optionService.getByPropertyOrDefault(QiniuOssProperties.OSS_THUMBNAIL_STYLE_RULE, String.class, "");
|
||||||
|
|
||||||
// Create configuration
|
// Create configuration
|
||||||
Configuration configuration = new Configuration(zone);
|
Configuration configuration = new Configuration(region);
|
||||||
|
|
||||||
// Create auth
|
// Create auth
|
||||||
Auth auth = Auth.create(accessKey, secretKey);
|
Auth auth = Auth.create(accessKey, secretKey);
|
||||||
// Build put plicy
|
// Build put plicy
|
||||||
StringMap putPolicy = new StringMap();
|
StringMap putPolicy = new StringMap();
|
||||||
putPolicy.put("returnBody", "{\"size\":$(fsize), " +
|
putPolicy.put("returnBody", "{\"key\":\"$(key)\",\"hash\":\"$(etag)\",\"size\":$(fsize),\"width\":$(imageInfo.width),\"height\":$(imageInfo.height)}");
|
||||||
"\"width\":$(imageInfo.width), " +
|
|
||||||
"\"height\":$(imageInfo.height)," +
|
|
||||||
" \"key\":\"$(key)\", " +
|
|
||||||
"\"hash\":\"$(etag)\"}");
|
|
||||||
// Get upload token
|
// Get upload token
|
||||||
String uploadToken = auth.uploadToken(bucket, null, 3600, putPolicy);
|
String uploadToken = auth.uploadToken(bucket, null, 60 * 60, putPolicy);
|
||||||
|
|
||||||
// Create temp path
|
// Create temp path
|
||||||
Path tmpPath = Paths.get(System.getProperty("java.io.tmpdir"), bucket);
|
Path tmpPath = Paths.get(System.getProperty("java.io.tmpdir"), bucket);
|
||||||
|
|
||||||
StringBuilder basePath = new StringBuilder(protocol)
|
StringBuilder basePath = new StringBuilder(protocol)
|
||||||
.append(domain)
|
.append(domain)
|
||||||
.append("/");
|
.append(URL_SEPARATOR);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String basename = FilenameUtils.getBasename(Objects.requireNonNull(file.getOriginalFilename()));
|
String basename = FilenameUtils.getBasename(Objects.requireNonNull(file.getOriginalFilename()));
|
||||||
|
@ -93,7 +91,7 @@ public class QiniuOssFileHandler implements FileHandler {
|
||||||
StringBuilder upFilePath = new StringBuilder();
|
StringBuilder upFilePath = new StringBuilder();
|
||||||
if (StringUtils.isNotEmpty(source)) {
|
if (StringUtils.isNotEmpty(source)) {
|
||||||
upFilePath.append(source)
|
upFilePath.append(source)
|
||||||
.append("/");
|
.append(URL_SEPARATOR);
|
||||||
}
|
}
|
||||||
upFilePath.append(basename)
|
upFilePath.append(basename)
|
||||||
.append("_")
|
.append("_")
|
||||||
|
@ -109,14 +107,12 @@ public class QiniuOssFileHandler implements FileHandler {
|
||||||
Response response = uploadManager.put(file.getInputStream(), upFilePath.toString(), uploadToken, null, null);
|
Response response = uploadManager.put(file.getInputStream(), upFilePath.toString(), uploadToken, null, null);
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("QnYun response: [{}]", response.toString());
|
log.debug("Qiniu oss response: [{}]", response.toString());
|
||||||
log.debug("QnYun response body: [{}]", response.bodyString());
|
log.debug("Qiniu oss response body: [{}]", response.bodyString());
|
||||||
}
|
}
|
||||||
|
|
||||||
response.jsonToObject(QiNiuPutSet.class);
|
|
||||||
|
|
||||||
// Convert response
|
// Convert response
|
||||||
QiNiuPutSet putSet = JsonUtils.jsonToObject(response.bodyString(), QiNiuPutSet.class);
|
PutSet putSet = JsonUtils.jsonToObject(response.bodyString(), PutSet.class);
|
||||||
|
|
||||||
// Get file full path
|
// Get file full path
|
||||||
String filePath = StringUtils.join(basePath.toString(), upFilePath.toString());
|
String filePath = StringUtils.join(basePath.toString(), upFilePath.toString());
|
||||||
|
@ -143,7 +139,7 @@ public class QiniuOssFileHandler implements FileHandler {
|
||||||
return result;
|
return result;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (e instanceof QiniuException) {
|
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);
|
throw new FileOperationException("上传附件 " + file.getOriginalFilename() + " 到七牛云失败", e);
|
||||||
|
@ -154,14 +150,14 @@ public class QiniuOssFileHandler implements FileHandler {
|
||||||
public void delete(String key) {
|
public void delete(String key) {
|
||||||
Assert.notNull(key, "File key must not be blank");
|
Assert.notNull(key, "File key must not be blank");
|
||||||
|
|
||||||
// Get all config
|
Region region = optionService.getQiniuRegion();
|
||||||
Zone zone = optionService.getQnYunZone();
|
|
||||||
String accessKey = optionService.getByPropertyOfNonNull(QiniuOssProperties.OSS_ACCESS_KEY).toString();
|
String accessKey = optionService.getByPropertyOfNonNull(QiniuOssProperties.OSS_ACCESS_KEY).toString();
|
||||||
String secretKey = optionService.getByPropertyOfNonNull(QiniuOssProperties.OSS_SECRET_KEY).toString();
|
String secretKey = optionService.getByPropertyOfNonNull(QiniuOssProperties.OSS_SECRET_KEY).toString();
|
||||||
String bucket = optionService.getByPropertyOfNonNull(QiniuOssProperties.OSS_BUCKET).toString();
|
String bucket = optionService.getByPropertyOfNonNull(QiniuOssProperties.OSS_BUCKET).toString();
|
||||||
|
|
||||||
// Create configuration
|
// Create configuration
|
||||||
Configuration configuration = new Configuration(zone);
|
Configuration configuration = new Configuration(region);
|
||||||
|
|
||||||
// Create auth
|
// Create auth
|
||||||
Auth auth = Auth.create(accessKey, secretKey);
|
Auth auth = Auth.create(accessKey, secretKey);
|
||||||
|
@ -169,9 +165,12 @@ public class QiniuOssFileHandler implements FileHandler {
|
||||||
BucketManager bucketManager = new BucketManager(auth, configuration);
|
BucketManager bucketManager = new BucketManager(auth, configuration);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
bucketManager.delete(bucket, key);
|
Response response = bucketManager.delete(bucket, key);
|
||||||
|
if (!response.isOK()) {
|
||||||
|
log.warn("附件 " + key + " 从七牛云删除失败");
|
||||||
|
}
|
||||||
} catch (QiniuException e) {
|
} catch (QiniuException e) {
|
||||||
log.error("QnYun error response: [{}]", e.response);
|
log.error("Qiniu oss error response: [{}]", e.response);
|
||||||
throw new FileOperationException("附件 " + key + " 从七牛云删除失败", e);
|
throw new FileOperationException("附件 " + key + " 从七牛云删除失败", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -180,4 +179,20 @@ public class QiniuOssFileHandler implements FileHandler {
|
||||||
public AttachmentType getAttachmentType() {
|
public AttachmentType getAttachmentType() {
|
||||||
return AttachmentType.QINIUOSS;
|
return AttachmentType.QINIUOSS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
private static class PutSet {
|
||||||
|
|
||||||
|
public String hash;
|
||||||
|
|
||||||
|
public String key;
|
||||||
|
|
||||||
|
private Long size;
|
||||||
|
|
||||||
|
private Integer width;
|
||||||
|
|
||||||
|
private Integer height;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,8 @@ import run.halo.app.utils.ImageUtils;
|
||||||
import javax.imageio.ImageReader;
|
import javax.imageio.ImageReader;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import static run.halo.app.model.support.HaloConst.URL_SEPARATOR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tencent cos file handler.
|
* Tencent cos file handler.
|
||||||
*
|
*
|
||||||
|
@ -68,13 +70,13 @@ public class TencentCosFileHandler implements FileHandler {
|
||||||
|
|
||||||
if (StringUtils.isNotEmpty(domain)) {
|
if (StringUtils.isNotEmpty(domain)) {
|
||||||
basePath.append(domain)
|
basePath.append(domain)
|
||||||
.append("/");
|
.append(URL_SEPARATOR);
|
||||||
} else {
|
} else {
|
||||||
basePath.append(bucketName)
|
basePath.append(bucketName)
|
||||||
.append(".cos.")
|
.append(".cos.")
|
||||||
.append(region)
|
.append(region)
|
||||||
.append(".myqcloud.com")
|
.append(".myqcloud.com")
|
||||||
.append("/");
|
.append(URL_SEPARATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -85,7 +87,7 @@ public class TencentCosFileHandler implements FileHandler {
|
||||||
|
|
||||||
if (StringUtils.isNotEmpty(source)) {
|
if (StringUtils.isNotEmpty(source)) {
|
||||||
upFilePath.append(source)
|
upFilePath.append(source)
|
||||||
.append("/");
|
.append(URL_SEPARATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
upFilePath.append(basename)
|
upFilePath.append(basename)
|
||||||
|
|
|
@ -2,8 +2,8 @@ package run.halo.app.listener.comment;
|
||||||
|
|
||||||
import cn.hutool.core.lang.Validator;
|
import cn.hutool.core.lang.Validator;
|
||||||
import cn.hutool.core.text.StrBuilder;
|
import cn.hutool.core.text.StrBuilder;
|
||||||
import cn.hutool.core.util.StrUtil;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.context.event.EventListener;
|
import org.springframework.context.event.EventListener;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
@ -175,7 +175,7 @@ public class CommentEventListener {
|
||||||
|
|
||||||
PostComment baseComment = postCommentService.getById(postComment.getParentId());
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ public class CommentEventListener {
|
||||||
|
|
||||||
SheetComment baseComment = sheetCommentService.getById(sheetComment.getParentId());
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,7 +234,7 @@ public class CommentEventListener {
|
||||||
|
|
||||||
JournalComment baseComment = journalCommentService.getById(journalComment.getParentId());
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package run.halo.app.listener.theme;
|
||||||
|
|
||||||
import org.springframework.context.event.EventListener;
|
import org.springframework.context.event.EventListener;
|
||||||
import org.springframework.stereotype.Component;
|
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.options.OptionUpdatedEvent;
|
||||||
import run.halo.app.event.theme.ThemeUpdatedEvent;
|
import run.halo.app.event.theme.ThemeUpdatedEvent;
|
||||||
import run.halo.app.service.ThemeService;
|
import run.halo.app.service.ThemeService;
|
||||||
|
@ -16,9 +16,9 @@ import run.halo.app.service.ThemeService;
|
||||||
@Component
|
@Component
|
||||||
public class ThemeUpdatedListener {
|
public class ThemeUpdatedListener {
|
||||||
|
|
||||||
private final StringCacheStore cacheStore;
|
private final AbstractStringCacheStore cacheStore;
|
||||||
|
|
||||||
public ThemeUpdatedListener(StringCacheStore cacheStore) {
|
public ThemeUpdatedListener(AbstractStringCacheStore cacheStore) {
|
||||||
this.cacheStore = cacheStore;
|
this.cacheStore = cacheStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class BasePostSimpleDTO extends BasePostMinimalDTO {
|
||||||
|
|
||||||
private String thumbnail;
|
private String thumbnail;
|
||||||
|
|
||||||
private Long visits = 0L;
|
private Long visits;
|
||||||
|
|
||||||
private Boolean disallowComment;
|
private Boolean disallowComment;
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ public class BasePostSimpleDTO extends BasePostMinimalDTO {
|
||||||
|
|
||||||
private String template;
|
private String template;
|
||||||
|
|
||||||
private Integer topPriority = 0;
|
private Integer topPriority;
|
||||||
|
|
||||||
private Long likes = 0L;
|
private Long likes;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,18 +11,39 @@ import org.springframework.lang.Nullable;
|
||||||
*/
|
*/
|
||||||
public enum InputType {
|
public enum InputType {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Text input type
|
||||||
|
*/
|
||||||
TEXT,
|
TEXT,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number input type
|
||||||
|
*/
|
||||||
NUMBER,
|
NUMBER,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Radio box input type
|
||||||
|
*/
|
||||||
RADIO,
|
RADIO,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select input type
|
||||||
|
*/
|
||||||
SELECT,
|
SELECT,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Textarea input type
|
||||||
|
*/
|
||||||
TEXTAREA,
|
TEXTAREA,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Color picker input type
|
||||||
|
*/
|
||||||
COLOR,
|
COLOR,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attachment picker input type
|
||||||
|
*/
|
||||||
ATTACHMENT;
|
ATTACHMENT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -7,17 +7,64 @@ package run.halo.app.model.enums;
|
||||||
*/
|
*/
|
||||||
public enum LogType implements ValueEnum<Integer> {
|
public enum LogType implements ValueEnum<Integer> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Blog initialization
|
||||||
|
*/
|
||||||
BLOG_INITIALIZED(0),
|
BLOG_INITIALIZED(0),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post published
|
||||||
|
*/
|
||||||
POST_PUBLISHED(5),
|
POST_PUBLISHED(5),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post edited
|
||||||
|
*/
|
||||||
POST_EDITED(15),
|
POST_EDITED(15),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post deleted
|
||||||
|
*/
|
||||||
POST_DELETED(20),
|
POST_DELETED(20),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logged in
|
||||||
|
*/
|
||||||
LOGGED_IN(25),
|
LOGGED_IN(25),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logged out
|
||||||
|
*/
|
||||||
LOGGED_OUT(30),
|
LOGGED_OUT(30),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logged failed.
|
||||||
|
*/
|
||||||
LOGIN_FAILED(35),
|
LOGIN_FAILED(35),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updated the blogger password
|
||||||
|
*/
|
||||||
PASSWORD_UPDATED(40),
|
PASSWORD_UPDATED(40),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updated the blogger profile
|
||||||
|
*/
|
||||||
PROFILE_UPDATED(45),
|
PROFILE_UPDATED(45),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sheet published
|
||||||
|
*/
|
||||||
SHEET_PUBLISHED(50),
|
SHEET_PUBLISHED(50),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sheet edited
|
||||||
|
*/
|
||||||
SHEET_EDITED(55),
|
SHEET_EDITED(55),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sheet deleted
|
||||||
|
*/
|
||||||
SHEET_DELETED(60);
|
SHEET_DELETED(60);
|
||||||
|
|
||||||
private final Integer value;
|
private final Integer value;
|
||||||
|
|
|
@ -11,9 +11,25 @@ import org.springframework.lang.Nullable;
|
||||||
* @date 19-6-10
|
* @date 19-6-10
|
||||||
*/
|
*/
|
||||||
public enum Mode {
|
public enum Mode {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Production mode
|
||||||
|
*/
|
||||||
PRODUCTION,
|
PRODUCTION,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Develop mode
|
||||||
|
*/
|
||||||
DEVELOPMENT,
|
DEVELOPMENT,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Demo mode
|
||||||
|
*/
|
||||||
DEMO,
|
DEMO,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test mode
|
||||||
|
*/
|
||||||
TEST;
|
TEST;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package run.halo.app.model.properties;
|
package run.halo.app.model.properties;
|
||||||
|
|
||||||
|
import run.halo.app.model.support.HaloConst;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ali yun oss properties.
|
* Ali yun oss properties.
|
||||||
*
|
*
|
||||||
|
@ -12,7 +14,7 @@ public enum AliOssProperties implements PropertyEnum {
|
||||||
/**
|
/**
|
||||||
* Aliyun oss domain protocol
|
* 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
|
* Aliyun oss domain
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package run.halo.app.model.properties;
|
package run.halo.app.model.properties;
|
||||||
|
|
||||||
|
import run.halo.app.model.support.HaloConst;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Baidu bos properties.
|
* Baidu bos properties.
|
||||||
*
|
*
|
||||||
|
@ -12,7 +14,7 @@ public enum BaiduBosProperties implements PropertyEnum {
|
||||||
/**
|
/**
|
||||||
* Baidu bos domain protocol.
|
* 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.
|
* Baidu bos domain.
|
||||||
|
|
|
@ -8,18 +8,39 @@ package run.halo.app.model.properties;
|
||||||
*/
|
*/
|
||||||
public enum EmailProperties implements PropertyEnum {
|
public enum EmailProperties implements PropertyEnum {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Email sender host
|
||||||
|
*/
|
||||||
HOST("email_host", String.class, ""),
|
HOST("email_host", String.class, ""),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Email sender protocol
|
||||||
|
*/
|
||||||
PROTOCOL("email_protocol", String.class, "smtp"),
|
PROTOCOL("email_protocol", String.class, "smtp"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SSL port
|
||||||
|
*/
|
||||||
SSL_PORT("email_ssl_port", Integer.class, "465"),
|
SSL_PORT("email_ssl_port", Integer.class, "465"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Email Sender username
|
||||||
|
*/
|
||||||
USERNAME("email_username", String.class, ""),
|
USERNAME("email_username", String.class, ""),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Email Sender password
|
||||||
|
*/
|
||||||
PASSWORD("email_password", String.class, ""),
|
PASSWORD("email_password", String.class, ""),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Email Sender name
|
||||||
|
*/
|
||||||
FROM_NAME("email_from_name", String.class, ""),
|
FROM_NAME("email_from_name", String.class, ""),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is enabled email sender
|
||||||
|
*/
|
||||||
ENABLED("email_enabled", Boolean.class, "false");
|
ENABLED("email_enabled", Boolean.class, "false");
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package run.halo.app.model.properties;
|
package run.halo.app.model.properties;
|
||||||
|
|
||||||
|
import run.halo.app.model.support.HaloConst;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Qiniu oss properties.
|
* Qiniu oss properties.
|
||||||
*
|
*
|
||||||
|
@ -32,7 +34,7 @@ public enum QiniuOssProperties implements PropertyEnum {
|
||||||
/**
|
/**
|
||||||
* Qiniu oss domain protocol.
|
* 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.
|
* Qiniu oss domain.
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package run.halo.app.model.properties;
|
package run.halo.app.model.properties;
|
||||||
|
|
||||||
|
import run.halo.app.model.support.HaloConst;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tencent cos properties.
|
* Tencent cos properties.
|
||||||
*
|
*
|
||||||
|
@ -12,7 +14,7 @@ public enum TencentCosProperties implements PropertyEnum {
|
||||||
/**
|
/**
|
||||||
* Tencent cos domain protocol.
|
* 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.
|
* Tencent cos domain.
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package run.halo.app.model.properties;
|
package run.halo.app.model.properties;
|
||||||
|
|
||||||
|
import run.halo.app.model.support.HaloConst;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upyun oss properties.
|
* Upyun oss properties.
|
||||||
*
|
*
|
||||||
|
@ -27,7 +29,7 @@ public enum UpOssProperties implements PropertyEnum {
|
||||||
/**
|
/**
|
||||||
* upyun oss domain protocol
|
* 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
|
* upyun oss domain
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
|
@ -24,6 +24,12 @@ public class HaloConst {
|
||||||
*/
|
*/
|
||||||
public final static String TEMP_DIR = System.getProperties().getProperty("java.io.tmpdir");
|
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.
|
* Halo backup prefix.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
|
@ -8,11 +8,11 @@ import org.springframework.util.AntPathMatcher;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.web.filter.OncePerRequestFilter;
|
import org.springframework.web.filter.OncePerRequestFilter;
|
||||||
import org.springframework.web.util.UrlPathHelper;
|
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.config.properties.HaloProperties;
|
||||||
|
import run.halo.app.exception.AbstractHaloException;
|
||||||
import run.halo.app.exception.BadRequestException;
|
import run.halo.app.exception.BadRequestException;
|
||||||
import run.halo.app.exception.ForbiddenException;
|
import run.halo.app.exception.ForbiddenException;
|
||||||
import run.halo.app.exception.HaloException;
|
|
||||||
import run.halo.app.exception.NotInstallException;
|
import run.halo.app.exception.NotInstallException;
|
||||||
import run.halo.app.model.enums.Mode;
|
import run.halo.app.model.enums.Mode;
|
||||||
import run.halo.app.model.properties.PrimaryProperties;
|
import run.halo.app.model.properties.PrimaryProperties;
|
||||||
|
@ -44,7 +44,7 @@ public abstract class AbstractAuthenticationFilter extends OncePerRequestFilter
|
||||||
protected final AntPathMatcher antPathMatcher;
|
protected final AntPathMatcher antPathMatcher;
|
||||||
protected final HaloProperties haloProperties;
|
protected final HaloProperties haloProperties;
|
||||||
protected final OptionService optionService;
|
protected final OptionService optionService;
|
||||||
protected final StringCacheStore cacheStore;
|
protected final AbstractStringCacheStore cacheStore;
|
||||||
private final UrlPathHelper urlPathHelper = new UrlPathHelper();
|
private final UrlPathHelper urlPathHelper = new UrlPathHelper();
|
||||||
private OneTimeTokenService oneTimeTokenService;
|
private OneTimeTokenService oneTimeTokenService;
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ public abstract class AbstractAuthenticationFilter extends OncePerRequestFilter
|
||||||
|
|
||||||
AbstractAuthenticationFilter(HaloProperties haloProperties,
|
AbstractAuthenticationFilter(HaloProperties haloProperties,
|
||||||
OptionService optionService,
|
OptionService optionService,
|
||||||
StringCacheStore cacheStore,
|
AbstractStringCacheStore cacheStore,
|
||||||
OneTimeTokenService oneTimeTokenService) {
|
OneTimeTokenService oneTimeTokenService) {
|
||||||
this.haloProperties = haloProperties;
|
this.haloProperties = haloProperties;
|
||||||
this.optionService = optionService;
|
this.optionService = optionService;
|
||||||
|
@ -189,7 +189,7 @@ public abstract class AbstractAuthenticationFilter extends OncePerRequestFilter
|
||||||
|
|
||||||
// Do authenticate
|
// Do authenticate
|
||||||
doAuthenticate(request, response, filterChain);
|
doAuthenticate(request, response, filterChain);
|
||||||
} catch (HaloException e) {
|
} catch (AbstractHaloException e) {
|
||||||
getFailureHandler().onFailure(request, response, e);
|
getFailureHandler().onFailure(request, response, e);
|
||||||
} finally {
|
} finally {
|
||||||
SecurityContextHolder.clearContext();
|
SecurityContextHolder.clearContext();
|
||||||
|
|
|
@ -6,7 +6,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
import org.springframework.stereotype.Component;
|
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.config.properties.HaloProperties;
|
||||||
import run.halo.app.exception.AuthenticationException;
|
import run.halo.app.exception.AuthenticationException;
|
||||||
import run.halo.app.model.entity.User;
|
import run.halo.app.model.entity.User;
|
||||||
|
@ -44,7 +44,7 @@ public class AdminAuthenticationFilter extends AbstractAuthenticationFilter {
|
||||||
|
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
|
||||||
public AdminAuthenticationFilter(StringCacheStore cacheStore,
|
public AdminAuthenticationFilter(AbstractStringCacheStore cacheStore,
|
||||||
UserService userService,
|
UserService userService,
|
||||||
HaloProperties haloProperties,
|
HaloProperties haloProperties,
|
||||||
OptionService optionService,
|
OptionService optionService,
|
||||||
|
|
|
@ -6,7 +6,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
import org.springframework.stereotype.Component;
|
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.config.properties.HaloProperties;
|
||||||
import run.halo.app.exception.AuthenticationException;
|
import run.halo.app.exception.AuthenticationException;
|
||||||
import run.halo.app.exception.ForbiddenException;
|
import run.halo.app.exception.ForbiddenException;
|
||||||
|
@ -40,7 +40,7 @@ public class ApiAuthenticationFilter extends AbstractAuthenticationFilter {
|
||||||
|
|
||||||
public ApiAuthenticationFilter(HaloProperties haloProperties,
|
public ApiAuthenticationFilter(HaloProperties haloProperties,
|
||||||
OptionService optionService,
|
OptionService optionService,
|
||||||
StringCacheStore cacheStore,
|
AbstractStringCacheStore cacheStore,
|
||||||
OneTimeTokenService oneTimeTokenService,
|
OneTimeTokenService oneTimeTokenService,
|
||||||
ObjectMapper objectMapper) {
|
ObjectMapper objectMapper) {
|
||||||
super(haloProperties, optionService, cacheStore, oneTimeTokenService);
|
super(haloProperties, optionService, cacheStore, oneTimeTokenService);
|
||||||
|
|
|
@ -2,7 +2,7 @@ package run.halo.app.security.filter;
|
||||||
|
|
||||||
import org.springframework.core.annotation.Order;
|
import org.springframework.core.annotation.Order;
|
||||||
import org.springframework.stereotype.Component;
|
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.config.properties.HaloProperties;
|
||||||
import run.halo.app.security.handler.ContentAuthenticationFailureHandler;
|
import run.halo.app.security.handler.ContentAuthenticationFailureHandler;
|
||||||
import run.halo.app.security.service.OneTimeTokenService;
|
import run.halo.app.security.service.OneTimeTokenService;
|
||||||
|
@ -27,7 +27,7 @@ public class ContentFilter extends AbstractAuthenticationFilter {
|
||||||
|
|
||||||
public ContentFilter(HaloProperties haloProperties,
|
public ContentFilter(HaloProperties haloProperties,
|
||||||
OptionService optionService,
|
OptionService optionService,
|
||||||
StringCacheStore cacheStore,
|
AbstractStringCacheStore cacheStore,
|
||||||
OneTimeTokenService oneTimeTokenService) {
|
OneTimeTokenService oneTimeTokenService) {
|
||||||
super(haloProperties, optionService, cacheStore, oneTimeTokenService);
|
super(haloProperties, optionService, cacheStore, oneTimeTokenService);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package run.halo.app.security.handler;
|
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.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
@ -23,5 +23,5 @@ public interface AuthenticationFailureHandler {
|
||||||
* @throws IOException io exception
|
* @throws IOException io exception
|
||||||
* @throws ServletException service 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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package run.halo.app.security.handler;
|
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 run.halo.app.exception.NotInstallException;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
|
@ -17,7 +17,7 @@ import java.io.IOException;
|
||||||
public class ContentAuthenticationFailureHandler implements AuthenticationFailureHandler {
|
public class ContentAuthenticationFailureHandler implements AuthenticationFailureHandler {
|
||||||
|
|
||||||
@Override
|
@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) {
|
if (exception instanceof NotInstallException) {
|
||||||
response.sendRedirect(request.getContextPath() + "/install");
|
response.sendRedirect(request.getContextPath() + "/install");
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -5,7 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.util.Assert;
|
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.model.support.BaseResponse;
|
||||||
import run.halo.app.utils.ExceptionUtils;
|
import run.halo.app.utils.ExceptionUtils;
|
||||||
import run.halo.app.utils.JsonUtils;
|
import run.halo.app.utils.JsonUtils;
|
||||||
|
@ -32,7 +32,7 @@ public class DefaultAuthenticationFailureHandler implements AuthenticationFailur
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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.warn("Handle unsuccessful authentication, ip: [{}]", ServletUtil.getClientIP(request));
|
||||||
log.error("Authentication failure", exception);
|
log.error("Authentication failure", exception);
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package run.halo.app.security.service.impl;
|
||||||
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.Assert;
|
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.security.service.OneTimeTokenService;
|
||||||
import run.halo.app.utils.HaloUtils;
|
import run.halo.app.utils.HaloUtils;
|
||||||
|
|
||||||
|
@ -22,9 +22,9 @@ public class OneTimeTokenServiceImpl implements OneTimeTokenService {
|
||||||
*/
|
*/
|
||||||
public static final int OTT_EXPIRED_DAY = 1;
|
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;
|
this.cacheStore = cacheStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package run.halo.app.service;
|
package run.halo.app.service;
|
||||||
|
|
||||||
import com.qiniu.common.Zone;
|
import com.qiniu.common.Zone;
|
||||||
|
import com.qiniu.storage.Region;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
|
@ -328,8 +329,17 @@ public interface OptionService extends CrudService<Option, Integer> {
|
||||||
* @return qiniu zone
|
* @return qiniu zone
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
|
@Deprecated
|
||||||
Zone getQnYunZone();
|
Zone getQnYunZone();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get qiniu oss region.
|
||||||
|
*
|
||||||
|
* @return qiniu region
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
Region getQiniuRegion();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets locale.
|
* Gets locale.
|
||||||
*
|
*
|
||||||
|
|
|
@ -12,7 +12,7 @@ import org.springframework.lang.NonNull;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.web.client.RestTemplate;
|
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.config.properties.HaloProperties;
|
||||||
import run.halo.app.event.logger.LogEvent;
|
import run.halo.app.event.logger.LogEvent;
|
||||||
import run.halo.app.exception.BadRequestException;
|
import run.halo.app.exception.BadRequestException;
|
||||||
|
@ -85,7 +85,7 @@ public class AdminServiceImpl implements AdminService {
|
||||||
|
|
||||||
private final MailService mailService;
|
private final MailService mailService;
|
||||||
|
|
||||||
private final StringCacheStore cacheStore;
|
private final AbstractStringCacheStore cacheStore;
|
||||||
|
|
||||||
private final RestTemplate restTemplate;
|
private final RestTemplate restTemplate;
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ public class AdminServiceImpl implements AdminService {
|
||||||
UserService userService,
|
UserService userService,
|
||||||
LinkService linkService,
|
LinkService linkService,
|
||||||
MailService mailService,
|
MailService mailService,
|
||||||
StringCacheStore cacheStore,
|
AbstractStringCacheStore cacheStore,
|
||||||
RestTemplate restTemplate,
|
RestTemplate restTemplate,
|
||||||
HaloProperties haloProperties,
|
HaloProperties haloProperties,
|
||||||
ApplicationEventPublisher eventPublisher,
|
ApplicationEventPublisher eventPublisher,
|
||||||
|
|
|
@ -25,6 +25,8 @@ import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static run.halo.app.model.support.HaloConst.URL_SEPARATOR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CategoryService implementation class.
|
* CategoryService implementation class.
|
||||||
*
|
*
|
||||||
|
@ -130,9 +132,9 @@ public class CategoryServiceImpl extends AbstractCrudService<Category, Integer>
|
||||||
fullPath.append(optionService.getBlogBaseUrl());
|
fullPath.append(optionService.getBlogBaseUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
fullPath.append("/")
|
fullPath.append(URL_SEPARATOR)
|
||||||
.append(optionService.getCategoriesPrefix())
|
.append(optionService.getCategoriesPrefix())
|
||||||
.append("/")
|
.append(URL_SEPARATOR)
|
||||||
.append(child.getSlug())
|
.append(child.getSlug())
|
||||||
.append(optionService.getPathSuffix());
|
.append(optionService.getPathSuffix());
|
||||||
|
|
||||||
|
@ -216,9 +218,9 @@ public class CategoryServiceImpl extends AbstractCrudService<Category, Integer>
|
||||||
fullPath.append(optionService.getBlogBaseUrl());
|
fullPath.append(optionService.getBlogBaseUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
fullPath.append("/")
|
fullPath.append(URL_SEPARATOR)
|
||||||
.append(optionService.getCategoriesPrefix())
|
.append(optionService.getCategoriesPrefix())
|
||||||
.append("/")
|
.append(URL_SEPARATOR)
|
||||||
.append(category.getSlug())
|
.append(category.getSlug())
|
||||||
.append(optionService.getPathSuffix());
|
.append(optionService.getPathSuffix());
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package run.halo.app.service.impl;
|
package run.halo.app.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
|
||||||
import com.qiniu.common.Zone;
|
import com.qiniu.common.Zone;
|
||||||
|
import com.qiniu.storage.Region;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
@ -15,7 +15,7 @@ import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.CollectionUtils;
|
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.config.properties.HaloProperties;
|
||||||
import run.halo.app.event.options.OptionUpdatedEvent;
|
import run.halo.app.event.options.OptionUpdatedEvent;
|
||||||
import run.halo.app.exception.MissingPropertyException;
|
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.OptionService;
|
||||||
import run.halo.app.service.base.AbstractCrudService;
|
import run.halo.app.service.base.AbstractCrudService;
|
||||||
import run.halo.app.utils.DateUtils;
|
import run.halo.app.utils.DateUtils;
|
||||||
import run.halo.app.utils.HaloUtils;
|
|
||||||
import run.halo.app.utils.ServiceUtils;
|
import run.halo.app.utils.ServiceUtils;
|
||||||
import run.halo.app.utils.ValidationUtils;
|
import run.halo.app.utils.ValidationUtils;
|
||||||
|
|
||||||
|
@ -52,7 +51,7 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
||||||
|
|
||||||
private final OptionRepository optionRepository;
|
private final OptionRepository optionRepository;
|
||||||
private final ApplicationContext applicationContext;
|
private final ApplicationContext applicationContext;
|
||||||
private final StringCacheStore cacheStore;
|
private final AbstractStringCacheStore cacheStore;
|
||||||
private final Map<String, PropertyEnum> propertyEnumMap;
|
private final Map<String, PropertyEnum> propertyEnumMap;
|
||||||
private final ApplicationEventPublisher eventPublisher;
|
private final ApplicationEventPublisher eventPublisher;
|
||||||
private HaloProperties haloProperties;
|
private HaloProperties haloProperties;
|
||||||
|
@ -60,7 +59,7 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
||||||
public OptionServiceImpl(HaloProperties haloProperties,
|
public OptionServiceImpl(HaloProperties haloProperties,
|
||||||
OptionRepository optionRepository,
|
OptionRepository optionRepository,
|
||||||
ApplicationContext applicationContext,
|
ApplicationContext applicationContext,
|
||||||
StringCacheStore cacheStore,
|
AbstractStringCacheStore cacheStore,
|
||||||
ApplicationEventPublisher eventPublisher) {
|
ApplicationEventPublisher eventPublisher) {
|
||||||
super(optionRepository);
|
super(optionRepository);
|
||||||
this.haloProperties = haloProperties;
|
this.haloProperties = haloProperties;
|
||||||
|
@ -433,6 +432,36 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
||||||
}).orElseGet(Zone::autoZone);
|
}).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
|
@Override
|
||||||
public Locale getLocale() {
|
public Locale getLocale() {
|
||||||
return getByProperty(BlogProperties.BLOG_LOCALE).map(localeStr -> {
|
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();
|
String blogUrl = getByProperty(BlogProperties.BLOG_URL).orElse("").toString();
|
||||||
|
|
||||||
if (StrUtil.isNotBlank(blogUrl)) {
|
if (StringUtils.isNotBlank(blogUrl)) {
|
||||||
blogUrl = StrUtil.removeSuffix(blogUrl, "/");
|
blogUrl = StringUtils.removeEnd(blogUrl, "/");
|
||||||
} else {
|
} else {
|
||||||
if (haloProperties.isProductionEnv()) {
|
|
||||||
blogUrl = String.format("http://%s:%s", "127.0.0.1", serverPort);
|
blogUrl = String.format("http://%s:%s", "127.0.0.1", serverPort);
|
||||||
} else {
|
|
||||||
blogUrl = String.format("http://%s:%s", HaloUtils.getMachineIP(), serverPort);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return blogUrl;
|
return blogUrl;
|
||||||
|
|
|
@ -24,6 +24,8 @@ import run.halo.app.utils.ServiceUtils;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static run.halo.app.model.support.HaloConst.URL_SEPARATOR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Post category service implementation.
|
* Post category service implementation.
|
||||||
*
|
*
|
||||||
|
@ -253,9 +255,9 @@ public class PostCategoryServiceImpl extends AbstractCrudService<PostCategory, I
|
||||||
fullPath.append(optionService.getBlogBaseUrl());
|
fullPath.append(optionService.getBlogBaseUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
fullPath.append("/")
|
fullPath.append(URL_SEPARATOR)
|
||||||
.append(optionService.getCategoriesPrefix())
|
.append(optionService.getCategoriesPrefix())
|
||||||
.append("/")
|
.append(URL_SEPARATOR)
|
||||||
.append(category.getSlug())
|
.append(category.getSlug())
|
||||||
.append(optionService.getPathSuffix());
|
.append(optionService.getPathSuffix());
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,8 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static run.halo.app.model.support.HaloConst.URL_SEPARATOR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PostCommentService implementation class
|
* PostCommentService implementation class
|
||||||
*
|
*
|
||||||
|
@ -125,11 +127,11 @@ public class PostCommentServiceImpl extends BaseCommentServiceImpl<PostComment>
|
||||||
fullPath.append(optionService.getBlogBaseUrl());
|
fullPath.append(optionService.getBlogBaseUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
fullPath.append("/");
|
fullPath.append(URL_SEPARATOR);
|
||||||
|
|
||||||
if (permalinkType.equals(PostPermalinkType.DEFAULT)) {
|
if (permalinkType.equals(PostPermalinkType.DEFAULT)) {
|
||||||
fullPath.append(archivesPrefix)
|
fullPath.append(archivesPrefix)
|
||||||
.append("/")
|
.append(URL_SEPARATOR)
|
||||||
.append(post.getSlug())
|
.append(post.getSlug())
|
||||||
.append(pathSuffix);
|
.append(pathSuffix);
|
||||||
} else if (permalinkType.equals(PostPermalinkType.ID)) {
|
} else if (permalinkType.equals(PostPermalinkType.ID)) {
|
||||||
|
@ -137,18 +139,18 @@ public class PostCommentServiceImpl extends BaseCommentServiceImpl<PostComment>
|
||||||
.append(post.getId());
|
.append(post.getId());
|
||||||
} else if (permalinkType.equals(PostPermalinkType.DATE)) {
|
} else if (permalinkType.equals(PostPermalinkType.DATE)) {
|
||||||
fullPath.append(DateUtil.year(post.getCreateTime()))
|
fullPath.append(DateUtil.year(post.getCreateTime()))
|
||||||
.append("/")
|
.append(URL_SEPARATOR)
|
||||||
.append(monthString)
|
.append(monthString)
|
||||||
.append("/")
|
.append(URL_SEPARATOR)
|
||||||
.append(post.getSlug())
|
.append(post.getSlug())
|
||||||
.append(pathSuffix);
|
.append(pathSuffix);
|
||||||
} else if (permalinkType.equals(PostPermalinkType.DAY)) {
|
} else if (permalinkType.equals(PostPermalinkType.DAY)) {
|
||||||
fullPath.append(DateUtil.year(post.getCreateTime()))
|
fullPath.append(DateUtil.year(post.getCreateTime()))
|
||||||
.append("/")
|
.append(URL_SEPARATOR)
|
||||||
.append(monthString)
|
.append(monthString)
|
||||||
.append("/")
|
.append(URL_SEPARATOR)
|
||||||
.append(dayString)
|
.append(dayString)
|
||||||
.append("/")
|
.append(URL_SEPARATOR)
|
||||||
.append(post.getSlug())
|
.append(post.getSlug())
|
||||||
.append(pathSuffix);
|
.append(pathSuffix);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package run.halo.app.service.impl;
|
package run.halo.app.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.text.StrBuilder;
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
|
@ -46,6 +44,7 @@ import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.springframework.data.domain.Sort.Direction.DESC;
|
import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||||
|
import static run.halo.app.model.support.HaloConst.URL_SEPARATOR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Post service implementation.
|
* Post service implementation.
|
||||||
|
@ -383,11 +382,11 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
|
||||||
post.setStatus(PostStatus.PUBLISHED);
|
post.setStatus(PostStatus.PUBLISHED);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StrUtil.isEmpty(post.getTitle())) {
|
if (StringUtils.isEmpty(post.getTitle())) {
|
||||||
post.setTitle(filename);
|
post.setTitle(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StrUtil.isEmpty(post.getSlug())) {
|
if (StringUtils.isEmpty(post.getSlug())) {
|
||||||
post.setSlug(SlugUtils.slug(post.getTitle()));
|
post.setSlug(SlugUtils.slug(post.getTitle()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,7 +406,7 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
|
||||||
public String exportMarkdown(Post post) {
|
public String exportMarkdown(Post post) {
|
||||||
Assert.notNull(post, "Post must not be null");
|
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("type: ").append("post").append("\n");
|
||||||
content.append("title: ").append(post.getTitle()).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(optionService.getBlogBaseUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
fullPath.append("/");
|
fullPath.append(URL_SEPARATOR);
|
||||||
|
|
||||||
if (permalinkType.equals(PostPermalinkType.DEFAULT)) {
|
if (permalinkType.equals(PostPermalinkType.DEFAULT)) {
|
||||||
fullPath.append(archivesPrefix)
|
fullPath.append(archivesPrefix)
|
||||||
.append("/")
|
.append(URL_SEPARATOR)
|
||||||
.append(post.getSlug())
|
.append(post.getSlug())
|
||||||
.append(pathSuffix);
|
.append(pathSuffix);
|
||||||
} else if (permalinkType.equals(PostPermalinkType.ID)) {
|
} else if (permalinkType.equals(PostPermalinkType.ID)) {
|
||||||
|
@ -897,18 +896,18 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
|
||||||
.append(post.getId());
|
.append(post.getId());
|
||||||
} else if (permalinkType.equals(PostPermalinkType.DATE)) {
|
} else if (permalinkType.equals(PostPermalinkType.DATE)) {
|
||||||
fullPath.append(DateUtil.year(post.getCreateTime()))
|
fullPath.append(DateUtil.year(post.getCreateTime()))
|
||||||
.append("/")
|
.append(URL_SEPARATOR)
|
||||||
.append(monthString)
|
.append(monthString)
|
||||||
.append("/")
|
.append(URL_SEPARATOR)
|
||||||
.append(post.getSlug())
|
.append(post.getSlug())
|
||||||
.append(pathSuffix);
|
.append(pathSuffix);
|
||||||
} else if (permalinkType.equals(PostPermalinkType.DAY)) {
|
} else if (permalinkType.equals(PostPermalinkType.DAY)) {
|
||||||
fullPath.append(DateUtil.year(post.getCreateTime()))
|
fullPath.append(DateUtil.year(post.getCreateTime()))
|
||||||
.append("/")
|
.append(URL_SEPARATOR)
|
||||||
.append(monthString)
|
.append(monthString)
|
||||||
.append("/")
|
.append(URL_SEPARATOR)
|
||||||
.append(dayString)
|
.append(dayString)
|
||||||
.append("/")
|
.append(URL_SEPARATOR)
|
||||||
.append(post.getSlug())
|
.append(post.getSlug())
|
||||||
.append(pathSuffix);
|
.append(pathSuffix);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,8 @@ import run.halo.app.utils.ServiceUtils;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static run.halo.app.model.support.HaloConst.URL_SEPARATOR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Post tag service implementation.
|
* Post tag service implementation.
|
||||||
*
|
*
|
||||||
|
@ -85,9 +87,9 @@ public class PostTagServiceImpl extends AbstractCrudService<PostTag, Integer> im
|
||||||
fullPath.append(optionService.getBlogBaseUrl());
|
fullPath.append(optionService.getBlogBaseUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
fullPath.append("/")
|
fullPath.append(URL_SEPARATOR)
|
||||||
.append(optionService.getTagsPrefix())
|
.append(optionService.getTagsPrefix())
|
||||||
.append("/")
|
.append(URL_SEPARATOR)
|
||||||
.append(tag.getSlug())
|
.append(tag.getSlug())
|
||||||
.append(optionService.getPathSuffix());
|
.append(optionService.getPathSuffix());
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,8 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static run.halo.app.model.support.HaloConst.URL_SEPARATOR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sheet comment service implementation.
|
* Sheet comment service implementation.
|
||||||
*
|
*
|
||||||
|
@ -97,9 +99,9 @@ public class SheetCommentServiceImpl extends BaseCommentServiceImpl<SheetComment
|
||||||
fullPath.append(optionService.getBlogBaseUrl());
|
fullPath.append(optionService.getBlogBaseUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
fullPath.append("/")
|
fullPath.append(URL_SEPARATOR)
|
||||||
.append(optionService.getSheetPrefix())
|
.append(optionService.getSheetPrefix())
|
||||||
.append("/")
|
.append(URL_SEPARATOR)
|
||||||
.append(basePostMinimalDTO.getSlug())
|
.append(basePostMinimalDTO.getSlug())
|
||||||
.append(optionService.getPathSuffix());
|
.append(optionService.getPathSuffix());
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package run.halo.app.service.impl;
|
package run.halo.app.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.text.StrBuilder;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
|
@ -31,6 +30,8 @@ import run.halo.app.utils.ServiceUtils;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static run.halo.app.model.support.HaloConst.URL_SEPARATOR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sheet service implementation.
|
* Sheet service implementation.
|
||||||
*
|
*
|
||||||
|
@ -173,7 +174,7 @@ public class SheetServiceImpl extends BasePostServiceImpl<Sheet> implements Shee
|
||||||
public String exportMarkdown(Sheet sheet) {
|
public String exportMarkdown(Sheet sheet) {
|
||||||
Assert.notNull(sheet, "Sheet must not be null");
|
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("type: ").append("sheet").append("\n");
|
||||||
content.append("title: ").append(sheet.getTitle()).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(optionService.getBlogBaseUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
fullPath.append("/")
|
fullPath.append(URL_SEPARATOR)
|
||||||
.append(optionService.getSheetPrefix())
|
.append(optionService.getSheetPrefix())
|
||||||
.append("/")
|
.append(URL_SEPARATOR)
|
||||||
.append(sheet.getSlug())
|
.append(sheet.getSlug())
|
||||||
.append(optionService.getPathSuffix());
|
.append(optionService.getPathSuffix());
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,8 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static run.halo.app.model.support.HaloConst.URL_SEPARATOR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TagService implementation class.
|
* TagService implementation class.
|
||||||
*
|
*
|
||||||
|
@ -84,9 +86,9 @@ public class TagServiceImpl extends AbstractCrudService<Tag, Integer> implements
|
||||||
fullPath.append(optionService.getBlogBaseUrl());
|
fullPath.append(optionService.getBlogBaseUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
fullPath.append("/")
|
fullPath.append(URL_SEPARATOR)
|
||||||
.append(optionService.getTagsPrefix())
|
.append(optionService.getTagsPrefix())
|
||||||
.append("/")
|
.append(URL_SEPARATOR)
|
||||||
.append(tag.getSlug())
|
.append(tag.getSlug())
|
||||||
.append(optionService.getPathSuffix());
|
.append(optionService.getPathSuffix());
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ import org.springframework.util.Assert;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
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.config.properties.HaloProperties;
|
||||||
import run.halo.app.event.theme.ThemeActivatedEvent;
|
import run.halo.app.event.theme.ThemeActivatedEvent;
|
||||||
import run.halo.app.event.theme.ThemeUpdatedEvent;
|
import run.halo.app.event.theme.ThemeUpdatedEvent;
|
||||||
|
@ -68,7 +68,7 @@ public class ThemeServiceImpl implements ThemeService {
|
||||||
|
|
||||||
private final OptionService optionService;
|
private final OptionService optionService;
|
||||||
|
|
||||||
private final StringCacheStore cacheStore;
|
private final AbstractStringCacheStore cacheStore;
|
||||||
|
|
||||||
private final ThemeConfigResolver themeConfigResolver;
|
private final ThemeConfigResolver themeConfigResolver;
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ public class ThemeServiceImpl implements ThemeService {
|
||||||
|
|
||||||
public ThemeServiceImpl(HaloProperties haloProperties,
|
public ThemeServiceImpl(HaloProperties haloProperties,
|
||||||
OptionService optionService,
|
OptionService optionService,
|
||||||
StringCacheStore cacheStore,
|
AbstractStringCacheStore cacheStore,
|
||||||
ThemeConfigResolver themeConfigResolver,
|
ThemeConfigResolver themeConfigResolver,
|
||||||
ThemePropertyResolver themePropertyResolver,
|
ThemePropertyResolver themePropertyResolver,
|
||||||
RestTemplate restTemplate,
|
RestTemplate restTemplate,
|
||||||
|
|
|
@ -7,7 +7,7 @@ import org.springframework.lang.NonNull;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
import run.halo.app.cache.StringCacheStore;
|
import run.halo.app.cache.AbstractStringCacheStore;
|
||||||
import run.halo.app.cache.lock.CacheLock;
|
import run.halo.app.cache.lock.CacheLock;
|
||||||
import run.halo.app.event.logger.LogEvent;
|
import run.halo.app.event.logger.LogEvent;
|
||||||
import run.halo.app.event.user.UserUpdatedEvent;
|
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 UserRepository userRepository;
|
||||||
|
|
||||||
private final StringCacheStore stringCacheStore;
|
private final AbstractStringCacheStore stringCacheStore;
|
||||||
|
|
||||||
private final ApplicationEventPublisher eventPublisher;
|
private final ApplicationEventPublisher eventPublisher;
|
||||||
|
|
||||||
public UserServiceImpl(UserRepository userRepository,
|
public UserServiceImpl(UserRepository userRepository,
|
||||||
StringCacheStore stringCacheStore,
|
AbstractStringCacheStore stringCacheStore,
|
||||||
ApplicationEventPublisher eventPublisher) {
|
ApplicationEventPublisher eventPublisher) {
|
||||||
super(userRepository);
|
super(userRepository);
|
||||||
this.userRepository = userRepository;
|
this.userRepository = userRepository;
|
||||||
|
|
|
@ -6,6 +6,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.lang.NonNull;
|
import org.springframework.lang.NonNull;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
import run.halo.app.model.support.HaloConst;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
@ -243,7 +244,7 @@ public class HaloUtils {
|
||||||
public static String normalizeUrl(@NonNull String originalUrl) {
|
public static String normalizeUrl(@NonNull String originalUrl) {
|
||||||
Assert.hasText(originalUrl, "Original Url must not be blank");
|
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, "//")) {
|
&& !StringUtils.startsWith(originalUrl, "//")) {
|
||||||
return originalUrl;
|
return originalUrl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package run.halo.app.utils;
|
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.lang.NonNull;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
@ -51,6 +51,6 @@ public class SlugUtils {
|
||||||
replaceAll("[\\?\\\\/:|<>\\*\\[\\]\\(\\)\\$%\\{\\}@~\\.]", "").
|
replaceAll("[\\?\\\\/:|<>\\*\\[\\]\\(\\)\\$%\\{\\}@~\\.]", "").
|
||||||
replaceAll("\\s", "")
|
replaceAll("\\s", "")
|
||||||
.toLowerCase(Locale.ENGLISH);
|
.toLowerCase(Locale.ENGLISH);
|
||||||
return StrUtil.isNotEmpty(slug) ? slug : String.valueOf(System.currentTimeMillis());
|
return StringUtils.isNotEmpty(slug) ? slug : String.valueOf(System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ import static org.junit.Assert.*;
|
||||||
*/
|
*/
|
||||||
public class CacheStoreTest {
|
public class CacheStoreTest {
|
||||||
|
|
||||||
private StringCacheStore cacheStore = new InMemoryCacheStore();
|
private AbstractStringCacheStore cacheStore = new InMemoryCacheStore();
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void putNullValueTest() {
|
public void putNullValueTest() {
|
||||||
|
|
|
@ -6,7 +6,7 @@ import org.junit.runner.RunWith;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
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.entity.Option;
|
||||||
import run.halo.app.model.properties.QiniuOssProperties;
|
import run.halo.app.model.properties.QiniuOssProperties;
|
||||||
import run.halo.app.repository.OptionRepository;
|
import run.halo.app.repository.OptionRepository;
|
||||||
|
@ -35,7 +35,7 @@ public class OptionServiceImplTest {
|
||||||
private OptionRepository optionRepository;
|
private OptionRepository optionRepository;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private StringCacheStore cacheStore;
|
private AbstractStringCacheStore cacheStore;
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private OptionServiceImpl optionService;
|
private OptionServiceImpl optionService;
|
||||||
|
|
Loading…
Reference in New Issue