mirror of https://github.com/halo-dev/halo
🎨 代码优化
parent
1d23670b5d
commit
09c6822640
|
@ -120,7 +120,7 @@ public class WebMvcAutoConfiguration implements WebMvcConfigurer {
|
|||
*/
|
||||
@Bean
|
||||
public LocaleResolver localeResolver() {
|
||||
SessionLocaleResolver slr = new SessionLocaleResolver();
|
||||
final SessionLocaleResolver slr = new SessionLocaleResolver();
|
||||
slr.setDefaultLocale(Locale.CHINA);
|
||||
return slr;
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ public class WebMvcAutoConfiguration implements WebMvcConfigurer {
|
|||
*/
|
||||
@Bean
|
||||
public LocaleChangeInterceptor localeChangeInterceptor() {
|
||||
LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
|
||||
final LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
|
||||
lci.setParamName("lang");
|
||||
return lci;
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
|
|||
* 加载主题设置
|
||||
*/
|
||||
private void loadActiveTheme() throws TemplateModelException {
|
||||
String themeValue = optionsService.findOneOption(BlogPropertiesEnum.THEME.getProp());
|
||||
final String themeValue = optionsService.findOneOption(BlogPropertiesEnum.THEME.getProp());
|
||||
if (StrUtil.isNotEmpty(themeValue) && !StrUtil.equals(themeValue, null)) {
|
||||
BaseController.THEME = themeValue;
|
||||
} else {
|
||||
|
@ -70,7 +70,7 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
|
|||
* 加载设置选项
|
||||
*/
|
||||
private void loadOptions() {
|
||||
Map<String, String> options = optionsService.findAllOptions();
|
||||
final Map<String, String> options = optionsService.findAllOptions();
|
||||
if (options != null && !options.isEmpty()) {
|
||||
HaloConst.OPTIONS = options;
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
|
|||
*/
|
||||
private void loadThemes() {
|
||||
HaloConst.THEMES.clear();
|
||||
List<Theme> themes = HaloUtils.getThemes();
|
||||
final List<Theme> themes = HaloUtils.getThemes();
|
||||
if (null != themes) {
|
||||
HaloConst.THEMES = themes;
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
|
|||
* 加载OwO表情
|
||||
*/
|
||||
private void loadOwo() {
|
||||
Map<String, String> map = new HashMap<>(135);
|
||||
final Map<String, String> map = new HashMap<>(135);
|
||||
map.put("@[nico]", "<img src='/static/halo-common/OwO/paopao/nico.png' alt='nico.png' style='vertical-align: middle;'>");
|
||||
map.put("@[OK]", "<img src='/static/halo-common/OwO/paopao/OK.png' alt='OK.png' style='vertical-align: middle;'>");
|
||||
map.put("@[what]", "<img src='/static/halo-common/OwO/paopao/what.png' alt='what.png' style='vertical-align: middle;'>");
|
||||
|
|
|
@ -29,7 +29,7 @@ public class ArticleTagDirective implements TemplateDirectiveModel {
|
|||
|
||||
@Override
|
||||
public void execute(Environment environment, Map map, TemplateModel[] templateModels, TemplateDirectiveBody templateDirectiveBody) throws TemplateException, IOException {
|
||||
DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25);
|
||||
final DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25);
|
||||
if (map.containsKey(METHOD_KEY)) {
|
||||
String method = map.get(METHOD_KEY).toString();
|
||||
switch (method) {
|
||||
|
|
|
@ -39,7 +39,7 @@ public class CommonTagDirective implements TemplateDirectiveModel {
|
|||
|
||||
@Override
|
||||
public void execute(Environment environment, Map map, TemplateModel[] templateModels, TemplateDirectiveBody templateDirectiveBody) throws TemplateException, IOException {
|
||||
DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25);
|
||||
final DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25);
|
||||
if (map.containsKey(METHOD_KEY)) {
|
||||
String method = map.get(METHOD_KEY).toString();
|
||||
switch (method) {
|
||||
|
|
|
@ -157,17 +157,17 @@ public class AttachmentServiceImpl implements AttachmentService {
|
|||
*/
|
||||
@Override
|
||||
public Map<String, String> attachUpload(MultipartFile file, HttpServletRequest request) {
|
||||
Map<String, String> resultMap = new HashMap<>(6);
|
||||
String dateString = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");
|
||||
final Map<String, String> resultMap = new HashMap<>(6);
|
||||
final String dateString = DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");
|
||||
try {
|
||||
//用户目录
|
||||
StrBuilder uploadPath = new StrBuilder(System.getProperties().getProperty("user.home"));
|
||||
final StrBuilder uploadPath = new StrBuilder(System.getProperties().getProperty("user.home"));
|
||||
uploadPath.append("/halo/");
|
||||
uploadPath.append("upload/");
|
||||
|
||||
//获取当前年月以创建目录,如果没有该目录则创建
|
||||
uploadPath.append(DateUtil.thisYear()).append("/").append(DateUtil.thisMonth()).append("/");
|
||||
File mediaPath = new File(uploadPath.toString());
|
||||
final File mediaPath = new File(uploadPath.toString());
|
||||
if (!mediaPath.exists()) {
|
||||
if (!mediaPath.mkdirs()) {
|
||||
resultMap.put("success", "0");
|
||||
|
@ -176,27 +176,27 @@ public class AttachmentServiceImpl implements AttachmentService {
|
|||
}
|
||||
|
||||
//不带后缀
|
||||
StrBuilder nameWithOutSuffix = new StrBuilder(file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf('.')).replaceAll(" ", "_").replaceAll(",", ""));
|
||||
final StrBuilder nameWithOutSuffix = new StrBuilder(file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf('.')).replaceAll(" ", "_").replaceAll(",", ""));
|
||||
nameWithOutSuffix.append(dateString);
|
||||
nameWithOutSuffix.append(new Random().nextInt(1000));
|
||||
|
||||
//文件后缀
|
||||
String fileSuffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf('.') + 1);
|
||||
final String fileSuffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf('.') + 1);
|
||||
|
||||
//带后缀
|
||||
StrBuilder fileName = new StrBuilder(nameWithOutSuffix);
|
||||
final StrBuilder fileName = new StrBuilder(nameWithOutSuffix);
|
||||
fileName.append(".");
|
||||
fileName.append(fileSuffix);
|
||||
|
||||
file.transferTo(new File(mediaPath.getAbsoluteFile(), fileName.toString()));
|
||||
|
||||
//文件原路径
|
||||
StrBuilder fullPath = new StrBuilder(mediaPath.getAbsolutePath());
|
||||
final StrBuilder fullPath = new StrBuilder(mediaPath.getAbsolutePath());
|
||||
fullPath.append("/");
|
||||
fullPath.append(fileName);
|
||||
|
||||
//压缩文件路径
|
||||
StrBuilder fullSmallPath = new StrBuilder(mediaPath.getAbsolutePath());
|
||||
final StrBuilder fullSmallPath = new StrBuilder(mediaPath.getAbsolutePath());
|
||||
fullSmallPath.append("/");
|
||||
fullSmallPath.append(nameWithOutSuffix);
|
||||
fullSmallPath.append("_small.");
|
||||
|
@ -206,7 +206,7 @@ public class AttachmentServiceImpl implements AttachmentService {
|
|||
Thumbnails.of(fullPath.toString()).size(256, 256).keepAspectRatio(false).toFile(fullSmallPath.toString());
|
||||
|
||||
//映射路径
|
||||
StrBuilder filePath = new StrBuilder("/upload/");
|
||||
final StrBuilder filePath = new StrBuilder("/upload/");
|
||||
filePath.append(DateUtil.thisYear());
|
||||
filePath.append("/");
|
||||
filePath.append(DateUtil.thisMonth());
|
||||
|
@ -214,7 +214,7 @@ public class AttachmentServiceImpl implements AttachmentService {
|
|||
filePath.append(fileName);
|
||||
|
||||
//缩略图映射路径
|
||||
StrBuilder fileSmallPath = new StrBuilder("/upload/");
|
||||
final StrBuilder fileSmallPath = new StrBuilder("/upload/");
|
||||
fileSmallPath.append(DateUtil.thisYear());
|
||||
fileSmallPath.append("/");
|
||||
fileSmallPath.append(DateUtil.thisMonth());
|
||||
|
@ -223,8 +223,8 @@ public class AttachmentServiceImpl implements AttachmentService {
|
|||
fileSmallPath.append("_small.");
|
||||
fileSmallPath.append(fileSuffix);
|
||||
|
||||
String size = HaloUtils.parseSize(new File(fullPath.toString()).length());
|
||||
String wh = HaloUtils.getImageWh(new File(fullPath.toString()));
|
||||
final String size = HaloUtils.parseSize(new File(fullPath.toString()).length());
|
||||
final String wh = HaloUtils.getImageWh(new File(fullPath.toString()));
|
||||
|
||||
resultMap.put("fileName", fileName.toString());
|
||||
resultMap.put("filePath", filePath.toString());
|
||||
|
@ -248,32 +248,32 @@ public class AttachmentServiceImpl implements AttachmentService {
|
|||
*/
|
||||
@Override
|
||||
public Map<String, String> attachQiNiuUpload(MultipartFile file, HttpServletRequest request) {
|
||||
Map<String, String> resultMap = new HashMap<>(6);
|
||||
final Map<String, String> resultMap = new HashMap<>(6);
|
||||
try {
|
||||
Configuration cfg = new Configuration(Zone.zone0());
|
||||
String key = Md5Util.getMD5Checksum(file);
|
||||
String accessKey = HaloConst.OPTIONS.get("qiniu_access_key");
|
||||
String secretKey = HaloConst.OPTIONS.get("qiniu_secret_key");
|
||||
String domain = HaloConst.OPTIONS.get("qiniu_domain");
|
||||
String bucket = HaloConst.OPTIONS.get("qiniu_bucket");
|
||||
String smallUrl = HaloConst.OPTIONS.get("qiniu_small_url");
|
||||
final Configuration cfg = new Configuration(Zone.zone0());
|
||||
final String key = Md5Util.getMD5Checksum(file);
|
||||
final String accessKey = HaloConst.OPTIONS.get("qiniu_access_key");
|
||||
final String secretKey = HaloConst.OPTIONS.get("qiniu_secret_key");
|
||||
final String domain = HaloConst.OPTIONS.get("qiniu_domain");
|
||||
final String bucket = HaloConst.OPTIONS.get("qiniu_bucket");
|
||||
final String smallUrl = HaloConst.OPTIONS.get("qiniu_small_url");
|
||||
if (StrUtil.isEmpty(accessKey) || StrUtil.isEmpty(secretKey) || StrUtil.isEmpty(domain) || StrUtil.isEmpty(bucket)) {
|
||||
return resultMap;
|
||||
}
|
||||
Auth auth = Auth.create(accessKey, secretKey);
|
||||
StringMap putPolicy = new StringMap();
|
||||
final Auth auth = Auth.create(accessKey, secretKey);
|
||||
final StringMap putPolicy = new StringMap();
|
||||
putPolicy.put("returnBody", "{\"size\":$(fsize),\"w\":$(imageInfo.width),\"h\":$(imageInfo.height)}");
|
||||
String upToken = auth.uploadToken(bucket, null, 3600, putPolicy);
|
||||
String localTempDir = Paths.get(System.getenv("java.io.tmpdir"), bucket).toString();
|
||||
final String upToken = auth.uploadToken(bucket, null, 3600, putPolicy);
|
||||
final String localTempDir = Paths.get(System.getenv("java.io.tmpdir"), bucket).toString();
|
||||
QiNiuPutSet putSet = new QiNiuPutSet();
|
||||
try {
|
||||
FileRecorder fileRecorder = new FileRecorder(localTempDir);
|
||||
UploadManager uploadManager = new UploadManager(cfg, fileRecorder);
|
||||
Response response = uploadManager.put(file.getInputStream(), key, upToken, null, null);
|
||||
final FileRecorder fileRecorder = new FileRecorder(localTempDir);
|
||||
final UploadManager uploadManager = new UploadManager(cfg, fileRecorder);
|
||||
final Response response = uploadManager.put(file.getInputStream(), key, upToken, null, null);
|
||||
//解析上传成功的结果
|
||||
putSet = new Gson().fromJson(response.bodyString(), QiNiuPutSet.class);
|
||||
} catch (QiniuException e) {
|
||||
Response r = e.response;
|
||||
final Response r = e.response;
|
||||
System.err.println(r.toString());
|
||||
try {
|
||||
System.err.println(r.bodyString());
|
||||
|
@ -285,7 +285,7 @@ public class AttachmentServiceImpl implements AttachmentService {
|
|||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String filePath = domain.trim() + "/" + key;
|
||||
final String filePath = domain.trim() + "/" + key;
|
||||
resultMap.put("fileName", file.getOriginalFilename());
|
||||
resultMap.put("filePath", filePath.trim());
|
||||
resultMap.put("smallPath", smallUrl == null ? filePath.trim() : (filePath + smallUrl).trim());
|
||||
|
@ -308,31 +308,31 @@ public class AttachmentServiceImpl implements AttachmentService {
|
|||
*/
|
||||
@Override
|
||||
public Map<String, String> attachUpYunUpload(MultipartFile file, HttpServletRequest request) {
|
||||
Map<String, String> resultMap = new HashMap<>(6);
|
||||
final Map<String, String> resultMap = new HashMap<>(6);
|
||||
try {
|
||||
String key = Md5Util.getMD5Checksum(file);
|
||||
String ossSrc = HaloConst.OPTIONS.get("upyun_oss_src");
|
||||
String ossPwd = HaloConst.OPTIONS.get("upyun_oss_pwd");
|
||||
String bucket = HaloConst.OPTIONS.get("upyun_oss_bucket");
|
||||
String domain = HaloConst.OPTIONS.get("upyun_oss_domain");
|
||||
String operator = HaloConst.OPTIONS.get("upyun_oss_operator");
|
||||
String smallUrl = HaloConst.OPTIONS.get("upyun_oss_small");
|
||||
final String key = Md5Util.getMD5Checksum(file);
|
||||
final String ossSrc = HaloConst.OPTIONS.get("upyun_oss_src");
|
||||
final String ossPwd = HaloConst.OPTIONS.get("upyun_oss_pwd");
|
||||
final String bucket = HaloConst.OPTIONS.get("upyun_oss_bucket");
|
||||
final String domain = HaloConst.OPTIONS.get("upyun_oss_domain");
|
||||
final String operator = HaloConst.OPTIONS.get("upyun_oss_operator");
|
||||
final String smallUrl = HaloConst.OPTIONS.get("upyun_oss_small");
|
||||
if (StrUtil.isEmpty(ossSrc) || StrUtil.isEmpty(ossPwd) || StrUtil.isEmpty(domain) || StrUtil.isEmpty(bucket) || StrUtil.isEmpty(operator)) {
|
||||
return resultMap;
|
||||
}
|
||||
String fileName = file.getOriginalFilename();
|
||||
String fileSuffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf('.'));
|
||||
UpYun upYun = new UpYun(bucket, operator, ossPwd);
|
||||
final String fileName = file.getOriginalFilename();
|
||||
final String fileSuffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf('.'));
|
||||
final UpYun upYun = new UpYun(bucket, operator, ossPwd);
|
||||
upYun.setTimeout(60);
|
||||
upYun.setApiDomain(UpYun.ED_AUTO);
|
||||
upYun.setDebug(true);
|
||||
upYun.writeFile(ossSrc + key + fileSuffix, file.getBytes(), true, null);
|
||||
String filePath = domain.trim() + ossSrc + key + fileSuffix;
|
||||
final String filePath = domain.trim() + ossSrc + key + fileSuffix;
|
||||
String smallPath = filePath;
|
||||
if (smallUrl != null) {
|
||||
smallPath += smallUrl;
|
||||
}
|
||||
BufferedImage image = ImageIO.read(file.getInputStream());
|
||||
final BufferedImage image = ImageIO.read(file.getInputStream());
|
||||
if (image != null) {
|
||||
resultMap.put("wh", image.getWidth() + "x" + image.getHeight());
|
||||
}
|
||||
|
@ -358,15 +358,15 @@ public class AttachmentServiceImpl implements AttachmentService {
|
|||
@Override
|
||||
public boolean deleteQiNiuAttachment(String key) {
|
||||
boolean flag = true;
|
||||
Configuration cfg = new Configuration(Zone.zone0());
|
||||
String accessKey = HaloConst.OPTIONS.get("qiniu_access_key");
|
||||
String secretKey = HaloConst.OPTIONS.get("qiniu_secret_key");
|
||||
String bucket = HaloConst.OPTIONS.get("qiniu_bucket");
|
||||
final Configuration cfg = new Configuration(Zone.zone0());
|
||||
final String accessKey = HaloConst.OPTIONS.get("qiniu_access_key");
|
||||
final String secretKey = HaloConst.OPTIONS.get("qiniu_secret_key");
|
||||
final String bucket = HaloConst.OPTIONS.get("qiniu_bucket");
|
||||
if (StrUtil.isEmpty(accessKey) || StrUtil.isEmpty(secretKey) || StrUtil.isEmpty(bucket)) {
|
||||
return false;
|
||||
}
|
||||
Auth auth = Auth.create(accessKey, secretKey);
|
||||
BucketManager bucketManager = new BucketManager(auth, cfg);
|
||||
final Auth auth = Auth.create(accessKey, secretKey);
|
||||
final BucketManager bucketManager = new BucketManager(auth, cfg);
|
||||
try {
|
||||
bucketManager.delete(bucket, key);
|
||||
} catch (QiniuException ex) {
|
||||
|
@ -386,14 +386,14 @@ public class AttachmentServiceImpl implements AttachmentService {
|
|||
@Override
|
||||
public boolean deleteUpYunAttachment(String fileName) {
|
||||
boolean flag = true;
|
||||
String ossSrc = HaloConst.OPTIONS.get("upyun_oss_src");
|
||||
String ossPwd = HaloConst.OPTIONS.get("upyun_oss_pwd");
|
||||
String bucket = HaloConst.OPTIONS.get("upyun_oss_bucket");
|
||||
String operator = HaloConst.OPTIONS.get("upyun_oss_operator");
|
||||
final String ossSrc = HaloConst.OPTIONS.get("upyun_oss_src");
|
||||
final String ossPwd = HaloConst.OPTIONS.get("upyun_oss_pwd");
|
||||
final String bucket = HaloConst.OPTIONS.get("upyun_oss_bucket");
|
||||
final String operator = HaloConst.OPTIONS.get("upyun_oss_operator");
|
||||
if (StrUtil.isEmpty(ossSrc) || StrUtil.isEmpty(ossPwd) || StrUtil.isEmpty(bucket) || StrUtil.isEmpty(operator)) {
|
||||
return false;
|
||||
}
|
||||
UpYun upYun = new UpYun(bucket, operator, ossPwd);
|
||||
final UpYun upYun = new UpYun(bucket, operator, ossPwd);
|
||||
upYun.setApiDomain(UpYun.ED_AUTO);
|
||||
try {
|
||||
flag = upYun.deleteFile(ossSrc + fileName);
|
||||
|
|
|
@ -48,7 +48,7 @@ public class CategoryServiceImpl implements CategoryService {
|
|||
@Override
|
||||
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Category remove(Long cateId) {
|
||||
Optional<Category> category = this.findByCateId(cateId);
|
||||
final Optional<Category> category = this.findByCateId(cateId);
|
||||
categoryRepository.delete(category.get());
|
||||
return category.get();
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ public class CategoryServiceImpl implements CategoryService {
|
|||
if (null == strings) {
|
||||
return null;
|
||||
}
|
||||
List<Category> categories = new ArrayList<>();
|
||||
final List<Category> categories = new ArrayList<>();
|
||||
Optional<Category> category = null;
|
||||
for (String str : strings) {
|
||||
category = findByCateId(Long.parseLong(str));
|
||||
|
|
|
@ -53,7 +53,7 @@ public class CommentServiceImpl implements CommentService {
|
|||
@Override
|
||||
@CacheEvict(value = {COMMENTS_CACHE_NAME, POSTS_CACHE_NAME}, allEntries = true, beforeInvocation = true)
|
||||
public Optional<Comment> remove(Long commentId) {
|
||||
Optional<Comment> comment = this.findCommentById(commentId);
|
||||
final Optional<Comment> comment = this.findCommentById(commentId);
|
||||
commentRepository.delete(comment.get());
|
||||
return comment;
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ public class CommentServiceImpl implements CommentService {
|
|||
@Override
|
||||
@CacheEvict(value = COMMENTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Comment updateCommentStatus(Long commentId, Integer status) {
|
||||
Optional<Comment> comment = findCommentById(commentId);
|
||||
final Optional<Comment> comment = findCommentById(commentId);
|
||||
comment.get().setCommentStatus(status);
|
||||
return commentRepository.save(comment.get());
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public class GalleryServiceImpl implements GalleryService {
|
|||
@Override
|
||||
@CacheEvict(value = GALLERIES_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Gallery remove(Long galleryId) {
|
||||
Optional<Gallery> gallery = this.findByGalleryId(galleryId);
|
||||
final Optional<Gallery> gallery = this.findByGalleryId(galleryId);
|
||||
galleryRepository.delete(gallery.get());
|
||||
return gallery.get();
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public class LinkServiceImpl implements LinkService {
|
|||
@Override
|
||||
@CacheEvict(value = LINKS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Link remove(Long linkId) {
|
||||
Optional<Link> link = this.findByLinkId(linkId);
|
||||
final Optional<Link> link = this.findByLinkId(linkId);
|
||||
linkRepository.delete(link.get());
|
||||
return link.get();
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ public class LogsServiceImpl implements LogsService {
|
|||
*/
|
||||
@Override
|
||||
public void save(String logTitle, String logContent, HttpServletRequest request) {
|
||||
Logs logs = new Logs();
|
||||
final Logs logs = new Logs();
|
||||
logs.setLogTitle(logTitle);
|
||||
logs.setLogContent(logContent);
|
||||
logs.setLogCreated(new Date());
|
||||
|
|
|
@ -70,7 +70,7 @@ public class MailServiceImpl implements MailService {
|
|||
HaloConst.OPTIONS.get(BlogPropertiesEnum.MAIL_SMTP_PASSWORD.getProp()));
|
||||
String text = "";
|
||||
try {
|
||||
Template template = freeMarker.getConfiguration().getTemplate(templateName);
|
||||
final Template template = freeMarker.getConfiguration().getTemplate(templateName);
|
||||
text = FreeMarkerTemplateUtils.processTemplateIntoString(template, content);
|
||||
OhMyEmail.subject(subject)
|
||||
.from(HaloConst.OPTIONS.get(BlogPropertiesEnum.MAIL_FROM_NAME.getProp()))
|
||||
|
@ -101,7 +101,7 @@ public class MailServiceImpl implements MailService {
|
|||
File file = new File(attachSrc);
|
||||
String text = "";
|
||||
try {
|
||||
Template template = freeMarker.getConfiguration().getTemplate(templateName);
|
||||
final Template template = freeMarker.getConfiguration().getTemplate(templateName);
|
||||
text = FreeMarkerTemplateUtils.processTemplateIntoString(template, content);
|
||||
OhMyEmail.subject(subject)
|
||||
.from(HaloConst.OPTIONS.get(BlogPropertiesEnum.MAIL_FROM_NAME.getProp()))
|
||||
|
|
|
@ -61,7 +61,7 @@ public class MenuServiceImpl implements MenuService {
|
|||
@Override
|
||||
@CacheEvict(value = MENUS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Menu remove(Long menuId) {
|
||||
Optional<Menu> menu = this.findByMenuId(menuId);
|
||||
final Optional<Menu> menu = this.findByMenuId(menuId);
|
||||
menuRepository.delete(menu.get());
|
||||
return menu.get();
|
||||
}
|
||||
|
|
|
@ -88,8 +88,8 @@ public class OptionsServiceImpl implements OptionsService {
|
|||
*/
|
||||
@Override
|
||||
public Map<String, String> findAllOptions() {
|
||||
Map<String, String> options = new HashMap<>();
|
||||
List<Options> optionsList = optionsRepository.findAll();
|
||||
final Map<String, String> options = new HashMap<>();
|
||||
final List<Options> optionsList = optionsRepository.findAll();
|
||||
if (null != optionsList) {
|
||||
optionsList.forEach(option -> options.put(option.getOptionName(), option.getOptionValue()));
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ public class OptionsServiceImpl implements OptionsService {
|
|||
*/
|
||||
@Override
|
||||
public String findOneOption(String key) {
|
||||
Options options = optionsRepository.findOptionsByOptionName(key);
|
||||
final Options options = optionsRepository.findOptionsByOptionName(key);
|
||||
if (null != options) {
|
||||
return options.getOptionValue();
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ public class PostServiceImpl implements PostService {
|
|||
@Override
|
||||
@CacheEvict(value = {POSTS_CACHE_NAME, COMMENTS_CACHE_NAME}, allEntries = true, beforeInvocation = true)
|
||||
public Post remove(Long postId) {
|
||||
Optional<Post> post = this.findByPostId(postId);
|
||||
final Optional<Post> post = this.findByPostId(postId);
|
||||
postRepository.delete(post.get());
|
||||
return post.get();
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ public class PostServiceImpl implements PostService {
|
|||
@Override
|
||||
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Post updatePostStatus(Long postId, Integer status) {
|
||||
Optional<Post> post = this.findByPostId(postId);
|
||||
final Optional<Post> post = this.findByPostId(postId);
|
||||
post.get().setPostStatus(status);
|
||||
return postRepository.save(post.get());
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ public class PostServiceImpl implements PostService {
|
|||
@Override
|
||||
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public void updateAllSummary(Integer postSummary) {
|
||||
List<Post> posts = this.findAll(PostTypeEnum.POST_TYPE_POST.getDesc());
|
||||
final List<Post> posts = this.findAll(PostTypeEnum.POST_TYPE_POST.getDesc());
|
||||
for (Post post : posts) {
|
||||
String text = StrUtil.cleanBlank(HtmlUtil.cleanHtmlTag(post.getPostContent()));
|
||||
if (text.length() > postSummary) {
|
||||
|
@ -251,8 +251,8 @@ public class PostServiceImpl implements PostService {
|
|||
@Override
|
||||
@Cacheable(value = POSTS_CACHE_NAME, key = "'archives_year_month'")
|
||||
public List<Archive> findPostGroupByYearAndMonth() {
|
||||
List<Object[]> objects = postRepository.findPostGroupByYearAndMonth();
|
||||
List<Archive> archives = new ArrayList<>();
|
||||
final List<Object[]> objects = postRepository.findPostGroupByYearAndMonth();
|
||||
final List<Archive> archives = new ArrayList<>();
|
||||
Archive archive = null;
|
||||
for (Object[] obj : objects) {
|
||||
archive = new Archive();
|
||||
|
@ -273,8 +273,8 @@ public class PostServiceImpl implements PostService {
|
|||
@Override
|
||||
@Cacheable(value = POSTS_CACHE_NAME, key = "'archives_year'")
|
||||
public List<Archive> findPostGroupByYear() {
|
||||
List<Object[]> objects = postRepository.findPostGroupByYear();
|
||||
List<Archive> archives = new ArrayList<>();
|
||||
final List<Object[]> objects = postRepository.findPostGroupByYear();
|
||||
final List<Archive> archives = new ArrayList<>();
|
||||
Archive archive = null;
|
||||
for (Object[] obj : objects) {
|
||||
archive = new Archive();
|
||||
|
@ -385,15 +385,15 @@ public class PostServiceImpl implements PostService {
|
|||
@CachePut(value = POSTS_CACHE_NAME, key = "'posts_related_'+#post.getPostId()")
|
||||
public List<Post> relatedPosts(Post post) {
|
||||
//获取当前文章的所有标签
|
||||
List<Tag> tags = post.getTags();
|
||||
List<Post> tempPosts = new ArrayList<>();
|
||||
final List<Tag> tags = post.getTags();
|
||||
final List<Post> tempPosts = new ArrayList<>();
|
||||
for (Tag tag : tags) {
|
||||
tempPosts.addAll(postRepository.findPostsByTags(tag));
|
||||
}
|
||||
//去掉当前的文章
|
||||
tempPosts.remove(post);
|
||||
//去掉重复的文章
|
||||
List<Post> allPosts = new ArrayList<>();
|
||||
final List<Post> allPosts = new ArrayList<>();
|
||||
for (int i = 0; i < tempPosts.size(); i++) {
|
||||
if (!allPosts.contains(tempPosts.get(i))) {
|
||||
allPosts.add(tempPosts.get(i));
|
||||
|
@ -475,10 +475,10 @@ public class PostServiceImpl implements PostService {
|
|||
*/
|
||||
@Override
|
||||
public Post buildCategoriesAndTags(Post post, List<String> cateList, String tagList) {
|
||||
List<Category> categories = categoryService.strListToCateList(cateList);
|
||||
final List<Category> categories = categoryService.strListToCateList(cateList);
|
||||
post.setCategories(categories);
|
||||
if (StrUtil.isNotEmpty(tagList)) {
|
||||
List<Tag> tags = tagService.strListToTagList(StrUtil.trim(tagList));
|
||||
final List<Tag> tags = tagService.strListToTagList(StrUtil.trim(tagList));
|
||||
post.setTags(tags);
|
||||
}
|
||||
return post;
|
||||
|
|
|
@ -48,7 +48,7 @@ public class TagServiceImpl implements TagService {
|
|||
@Override
|
||||
@CacheEvict(value = POSTS_CACHE_NAME, allEntries = true, beforeInvocation = true)
|
||||
public Tag remove(Long tagId) {
|
||||
Optional<Tag> tag = findByTagId(tagId);
|
||||
final Optional<Tag> tag = findByTagId(tagId);
|
||||
tagRepository.delete(tag.get());
|
||||
return tag.get();
|
||||
}
|
||||
|
@ -104,10 +104,10 @@ public class TagServiceImpl implements TagService {
|
|||
*/
|
||||
@Override
|
||||
public List<Tag> strListToTagList(String tagList) {
|
||||
String[] tags = tagList.split(",");
|
||||
List<Tag> tagsList = new ArrayList<>();
|
||||
final String[] tags = tagList.split(",");
|
||||
final List<Tag> tagsList = new ArrayList<>();
|
||||
for (String tag : tags) {
|
||||
Tag t = findTagByTagName(tag);
|
||||
final Tag t = findTagByTagName(tag);
|
||||
Tag nt = null;
|
||||
if (null != t) {
|
||||
tagsList.add(t);
|
||||
|
|
|
@ -65,7 +65,7 @@ public class UserServiceImpl implements UserService {
|
|||
*/
|
||||
@Override
|
||||
public User findUser() {
|
||||
List<User> users = userRepository.findAll();
|
||||
final List<User> users = userRepository.findAll();
|
||||
if (users != null && users.size() > 0) {
|
||||
return users.get(0);
|
||||
} else {
|
||||
|
@ -92,7 +92,7 @@ public class UserServiceImpl implements UserService {
|
|||
*/
|
||||
@Override
|
||||
public void updateUserLoginEnable(String enable) {
|
||||
User user = this.findUser();
|
||||
final User user = this.findUser();
|
||||
user.setLoginEnable(enable);
|
||||
userRepository.save(user);
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ public class UserServiceImpl implements UserService {
|
|||
*/
|
||||
@Override
|
||||
public User updateUserLoginLast(Date lastDate) {
|
||||
User user = this.findUser();
|
||||
final User user = this.findUser();
|
||||
user.setLoginLast(lastDate);
|
||||
userRepository.save(user);
|
||||
return user;
|
||||
|
@ -118,7 +118,7 @@ public class UserServiceImpl implements UserService {
|
|||
*/
|
||||
@Override
|
||||
public Integer updateUserLoginError() {
|
||||
User user = this.findUser();
|
||||
final User user = this.findUser();
|
||||
user.setLoginError((user.getLoginError() == null ? 0 : user.getLoginError()) + 1);
|
||||
userRepository.save(user);
|
||||
return user.getLoginError();
|
||||
|
@ -131,7 +131,7 @@ public class UserServiceImpl implements UserService {
|
|||
*/
|
||||
@Override
|
||||
public User updateUserNormal() {
|
||||
User user = this.findUser();
|
||||
final User user = this.findUser();
|
||||
user.setLoginEnable(TrueFalseEnum.TRUE.getDesc());
|
||||
user.setLoginError(0);
|
||||
user.setLoginLast(new Date());
|
||||
|
|
|
@ -17,7 +17,7 @@ public class PostSyncTask {
|
|||
* 将缓存的图文浏览数写入数据库
|
||||
*/
|
||||
public void postSync() {
|
||||
PostService postService = SpringUtil.getBean(PostService.class);
|
||||
final PostService postService = SpringUtil.getBean(PostService.class);
|
||||
Post post = null;
|
||||
int count = 0;
|
||||
for (Long key : HaloConst.POSTS_VIEWS.keySet()) {
|
||||
|
|
|
@ -29,7 +29,7 @@ public class CommentUtil {
|
|||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<Comment> commentsResult = new ArrayList<>();
|
||||
final List<Comment> commentsResult = new ArrayList<>();
|
||||
|
||||
for (Comment comment : commentsRoot) {
|
||||
if (comment.getCommentParent() == 0) {
|
||||
|
@ -59,7 +59,7 @@ public class CommentUtil {
|
|||
return null;
|
||||
}
|
||||
|
||||
List<Comment> commentsChild = new ArrayList<>();
|
||||
final List<Comment> commentsChild = new ArrayList<>();
|
||||
for (Comment comment : commentsRoot) {
|
||||
if (comment.getCommentParent() != 0) {
|
||||
if (comment.getCommentParent().equals(id)) {
|
||||
|
|
|
@ -48,15 +48,16 @@ public class HaloUtils {
|
|||
* 获取备份文件信息
|
||||
*
|
||||
* @param dir dir
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
public static List<BackupDto> getBackUps(String dir) {
|
||||
StrBuilder srcPathStr = new StrBuilder(System.getProperties().getProperty("user.home"));
|
||||
final StrBuilder srcPathStr = new StrBuilder(System.getProperties().getProperty("user.home"));
|
||||
srcPathStr.append("/halo/backup/");
|
||||
srcPathStr.append(dir);
|
||||
File srcPath = new File(srcPathStr.toString());
|
||||
File[] files = srcPath.listFiles();
|
||||
List<BackupDto> backupDtos = new ArrayList<>();
|
||||
final File srcPath = new File(srcPathStr.toString());
|
||||
final File[] files = srcPath.listFiles();
|
||||
final List<BackupDto> backupDtos = new ArrayList<>();
|
||||
BackupDto backupDto = null;
|
||||
// 遍历文件
|
||||
if (null != files) {
|
||||
|
@ -82,25 +83,26 @@ public class HaloUtils {
|
|||
* 转换文件大小
|
||||
*
|
||||
* @param size size
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public static String parseSize(long size) {
|
||||
if (size < CommonParamsEnum.BYTE.getValue()) {
|
||||
return String.valueOf(size) + "B";
|
||||
return size + "B";
|
||||
} else {
|
||||
size = size / 1024;
|
||||
}
|
||||
if (size < CommonParamsEnum.BYTE.getValue()) {
|
||||
return String.valueOf(size) + "KB";
|
||||
return size + "KB";
|
||||
} else {
|
||||
size = size / 1024;
|
||||
}
|
||||
if (size < CommonParamsEnum.BYTE.getValue()) {
|
||||
size = size * 100;
|
||||
return String.valueOf((size / 100)) + "." + String.valueOf((size % 100)) + "MB";
|
||||
return size / 100 + "." + size % 100 + "MB";
|
||||
} else {
|
||||
size = size * 100 / 1024;
|
||||
return String.valueOf((size / 100)) + "." + String.valueOf((size % 100)) + "GB";
|
||||
return size / 100 + "." + size % 100 + "GB";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,21 +110,21 @@ public class HaloUtils {
|
|||
* 获取文件创建时间
|
||||
*
|
||||
* @param srcPath 文件绝对路径
|
||||
*
|
||||
* @return 时间
|
||||
*/
|
||||
public static Date getCreateTime(String srcPath) {
|
||||
Path path = Paths.get(srcPath);
|
||||
BasicFileAttributeView basicview = Files.getFileAttributeView(path, BasicFileAttributeView.class,
|
||||
LinkOption.NOFOLLOW_LINKS);
|
||||
final Path path = Paths.get(srcPath);
|
||||
final BasicFileAttributeView basicview = Files.getFileAttributeView(path, BasicFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
|
||||
BasicFileAttributes attr;
|
||||
try {
|
||||
attr = basicview.readAttributes();
|
||||
Date createDate = new Date(attr.creationTime().toMillis());
|
||||
final Date createDate = new Date(attr.creationTime().toMillis());
|
||||
return createDate;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Calendar cal = Calendar.getInstance();
|
||||
final Calendar cal = Calendar.getInstance();
|
||||
cal.set(1970, 0, 1, 0, 0, 0);
|
||||
return cal.getTime();
|
||||
}
|
||||
|
@ -131,11 +133,12 @@ public class HaloUtils {
|
|||
* 获取文件长和宽
|
||||
*
|
||||
* @param file file
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public static String getImageWh(File file) {
|
||||
try {
|
||||
BufferedImage image = ImageIO.read(new FileInputStream(file));
|
||||
final BufferedImage image = ImageIO.read(new FileInputStream(file));
|
||||
return image.getWidth() + "x" + image.getHeight();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -149,13 +152,13 @@ public class HaloUtils {
|
|||
* @return List
|
||||
*/
|
||||
public static List<Theme> getThemes() {
|
||||
List<Theme> themes = new ArrayList<>();
|
||||
final List<Theme> themes = new ArrayList<>();
|
||||
try {
|
||||
// 获取项目根路径
|
||||
File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
final File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
// 获取主题路径
|
||||
File themesPath = new File(basePath.getAbsolutePath(), "templates/themes");
|
||||
File[] files = themesPath.listFiles();
|
||||
final File themesPath = new File(basePath.getAbsolutePath(), "templates/themes");
|
||||
final File[] files = themesPath.listFiles();
|
||||
if (null != files) {
|
||||
Theme theme = null;
|
||||
for (File file : files) {
|
||||
|
@ -192,18 +195,19 @@ public class HaloUtils {
|
|||
* 获取主题下的模板文件名
|
||||
*
|
||||
* @param theme theme
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
public static List<String> getTplName(String theme) {
|
||||
List<String> tpls = new ArrayList<>();
|
||||
final List<String> tpls = new ArrayList<>();
|
||||
try {
|
||||
// 获取项目根路径
|
||||
File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
final File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
// 获取主题路径
|
||||
File themesPath = new File(basePath.getAbsolutePath(), "templates/themes/" + theme);
|
||||
File modulePath = new File(themesPath.getAbsolutePath(), "module");
|
||||
File[] baseFiles = themesPath.listFiles();
|
||||
File[] moduleFiles = modulePath.listFiles();
|
||||
final File themesPath = new File(basePath.getAbsolutePath(), "templates/themes/" + theme);
|
||||
final File modulePath = new File(themesPath.getAbsolutePath(), "module");
|
||||
final File[] baseFiles = themesPath.listFiles();
|
||||
final File[] moduleFiles = modulePath.listFiles();
|
||||
if (null != moduleFiles) {
|
||||
for (File file : moduleFiles) {
|
||||
if (file.isFile() && file.getName().endsWith(".ftl")) {
|
||||
|
@ -230,12 +234,12 @@ public class HaloUtils {
|
|||
* @return List
|
||||
*/
|
||||
public static List<String> getCustomTpl(String theme) {
|
||||
List<String> tpls = new ArrayList<>();
|
||||
final List<String> tpls = new ArrayList<>();
|
||||
try {
|
||||
File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
final File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
// 获取主题路径
|
||||
File themePath = new File(basePath.getAbsolutePath(), "templates/themes/" + theme);
|
||||
File[] themeFiles = themePath.listFiles();
|
||||
final File themePath = new File(basePath.getAbsolutePath(), "templates/themes/" + theme);
|
||||
final File[] themeFiles = themePath.listFiles();
|
||||
if (null != themeFiles && themeFiles.length > 0) {
|
||||
for (File file : themeFiles) {
|
||||
String[] split = StrUtil.removeSuffix(file.getName(), ".ftl").split("_");
|
||||
|
@ -261,7 +265,7 @@ public class HaloUtils {
|
|||
FileWriter fileWriter = null;
|
||||
BufferedWriter bufferedWriter = null;
|
||||
try {
|
||||
File file = new File(filePath);
|
||||
final File file = new File(filePath);
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
}
|
||||
|
@ -284,13 +288,15 @@ public class HaloUtils {
|
|||
* 生成rss
|
||||
*
|
||||
* @param posts posts
|
||||
*
|
||||
* @return String
|
||||
*
|
||||
* @throws FeedException FeedException
|
||||
*/
|
||||
public static String getRss(List<Post> posts) throws FeedException {
|
||||
Assert.notEmpty(posts, "posts must not be empty");
|
||||
|
||||
Channel channel = new Channel("rss_2.0");
|
||||
final Channel channel = new Channel("rss_2.0");
|
||||
if (null == HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp())) {
|
||||
channel.setTitle("");
|
||||
} else {
|
||||
|
@ -307,13 +313,13 @@ public class HaloUtils {
|
|||
channel.setDescription(HaloConst.OPTIONS.get(BlogPropertiesEnum.SEO_DESC.getProp()));
|
||||
}
|
||||
channel.setLanguage("zh-CN");
|
||||
List<Item> items = new ArrayList<>();
|
||||
final List<Item> items = new ArrayList<>();
|
||||
for (Post post : posts) {
|
||||
Item item = new Item();
|
||||
final Item item = new Item();
|
||||
item.setTitle(post.getPostTitle());
|
||||
Content content = new Content();
|
||||
final Content content = new Content();
|
||||
String value = post.getPostContent();
|
||||
char[] xmlChar = value.toCharArray();
|
||||
final char[] xmlChar = value.toCharArray();
|
||||
for (int i = 0; i < xmlChar.length; ++i) {
|
||||
if (xmlChar[i] > 0xFFFD) {
|
||||
xmlChar[i] = ' ';
|
||||
|
@ -324,13 +330,12 @@ public class HaloUtils {
|
|||
value = new String(xmlChar);
|
||||
content.setValue(value);
|
||||
item.setContent(content);
|
||||
item.setLink(
|
||||
HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/archives/" + post.getPostUrl());
|
||||
item.setLink(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/archives/" + post.getPostUrl());
|
||||
item.setPubDate(post.getPostDate());
|
||||
items.add(item);
|
||||
}
|
||||
channel.setItems(items);
|
||||
WireFeedOutput out = new WireFeedOutput();
|
||||
final WireFeedOutput out = new WireFeedOutput();
|
||||
return out.outputString(channel);
|
||||
}
|
||||
|
||||
|
@ -338,13 +343,14 @@ public class HaloUtils {
|
|||
* 获取sitemap
|
||||
*
|
||||
* @param posts posts
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public static String getSiteMap(List<Post> posts) {
|
||||
Assert.notEmpty(posts, "post mut not be empty");
|
||||
StrBuilder head = new StrBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">");
|
||||
StrBuilder urlBody = new StrBuilder();
|
||||
String urlPath = HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/archives/";
|
||||
final StrBuilder head = new StrBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">");
|
||||
final StrBuilder urlBody = new StrBuilder();
|
||||
final String urlPath = HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/archives/";
|
||||
for (Post post : posts) {
|
||||
urlBody.append("<url><loc>");
|
||||
urlBody.append(urlPath);
|
||||
|
@ -364,7 +370,7 @@ public class HaloUtils {
|
|||
* @param password password
|
||||
*/
|
||||
public static void configMail(String smtpHost, String userName, String password) {
|
||||
Properties properties = OhMyEmail.defaultConfig(false);
|
||||
final Properties properties = OhMyEmail.defaultConfig(false);
|
||||
properties.setProperty("mail.smtp.host", smtpHost);
|
||||
OhMyEmail.config(properties, userName, password);
|
||||
}
|
||||
|
@ -375,6 +381,7 @@ public class HaloUtils {
|
|||
* @param blogUrl 博客地址
|
||||
* @param token 百度推送token
|
||||
* @param urls 文章路径
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public static String baiduPost(String blogUrl, String token, String urls) {
|
||||
|
@ -382,17 +389,17 @@ public class HaloUtils {
|
|||
Assert.hasText(token, "token must not be blank");
|
||||
Assert.hasText(urls, "urls must not be blank");
|
||||
|
||||
StrBuilder url = new StrBuilder("http://data.zz.baidu.com/urls?site=");
|
||||
final StrBuilder url = new StrBuilder("http://data.zz.baidu.com/urls?site=");
|
||||
url.append(blogUrl);
|
||||
url.append("&token=");
|
||||
url.append(token);
|
||||
|
||||
StrBuilder result = new StrBuilder();
|
||||
final StrBuilder result = new StrBuilder();
|
||||
PrintWriter out = null;
|
||||
BufferedReader in = null;
|
||||
try {
|
||||
// 建立URL之间的连接
|
||||
URLConnection conn = new URL(url.toString()).openConnection();
|
||||
final URLConnection conn = new URL(url.toString()).openConnection();
|
||||
// 设置通用的请求属性
|
||||
conn.setRequestProperty("Host", "data.zz.baidu.com");
|
||||
conn.setRequestProperty("User-Agent", "curl/7.12.1");
|
||||
|
|
|
@ -43,10 +43,11 @@ public class MarkdownUtils {
|
|||
* 渲染Markdown
|
||||
*
|
||||
* @param content content
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public static String renderMarkdown(String content) {
|
||||
Node document = PARSER.parse(content);
|
||||
final Node document = PARSER.parse(content);
|
||||
return RENDERER.render(document);
|
||||
}
|
||||
|
||||
|
@ -54,11 +55,12 @@ public class MarkdownUtils {
|
|||
* 获取元数据
|
||||
*
|
||||
* @param content content
|
||||
*
|
||||
* @return Map
|
||||
*/
|
||||
public static Map<String, List<String>> getFrontMatter(String content) {
|
||||
YamlFrontMatterVisitor visitor = new YamlFrontMatterVisitor();
|
||||
Node document = PARSER.parse(content);
|
||||
final YamlFrontMatterVisitor visitor = new YamlFrontMatterVisitor();
|
||||
final Node document = PARSER.parse(content);
|
||||
document.accept(visitor);
|
||||
return visitor.getData();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cc.ryanc.halo.utils;
|
||||
|
||||
import cn.hutool.core.text.StrBuilder;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
@ -17,15 +18,18 @@ public class Md5Util {
|
|||
|
||||
/**
|
||||
* 计算文件MD5编码
|
||||
* @param file
|
||||
* @return
|
||||
* @throws Exception
|
||||
*
|
||||
* @param file file
|
||||
*
|
||||
* @return byte
|
||||
*
|
||||
* @throws Exception Exception
|
||||
*/
|
||||
public static byte[] createChecksum(MultipartFile file) throws Exception {
|
||||
InputStream fis = file.getInputStream();
|
||||
private static byte[] createChecksum(MultipartFile file) throws Exception {
|
||||
final InputStream fis = file.getInputStream();
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
MessageDigest complete = MessageDigest.getInstance("MD5");
|
||||
final byte[] buffer = new byte[1024];
|
||||
final MessageDigest complete = MessageDigest.getInstance("MD5");
|
||||
int numRead;
|
||||
|
||||
do {
|
||||
|
@ -41,18 +45,20 @@ public class Md5Util {
|
|||
|
||||
/**
|
||||
* 生成文件hash值
|
||||
* @param file
|
||||
* @return
|
||||
* @throws Exception
|
||||
*
|
||||
* @param file file
|
||||
*
|
||||
* @return String
|
||||
*
|
||||
* @throws Exception Exception
|
||||
*/
|
||||
public static String getMD5Checksum(MultipartFile file) throws Exception {
|
||||
byte[] b = createChecksum(file);
|
||||
String result = "";
|
||||
final byte[] b = createChecksum(file);
|
||||
StrBuilder result = new StrBuilder();
|
||||
|
||||
for (int i=0; i < b.length; i++) {
|
||||
result += Integer.toString( ( b[i] & 0xff ) + 0x100, 16).substring( 1 );
|
||||
for (int i = 0; i < b.length; i++) {
|
||||
result.append(Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1));
|
||||
}
|
||||
return result;
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -78,38 +78,39 @@ public class AdminController extends BaseController {
|
|||
*
|
||||
* @param model model
|
||||
* @param session session
|
||||
*
|
||||
* @return 模板路径admin/admin_index
|
||||
*/
|
||||
@GetMapping(value = {"", "/index"})
|
||||
public String index(Model model) {
|
||||
|
||||
//查询评论的条数
|
||||
Long commentCount = commentService.getCount();
|
||||
final Long commentCount = commentService.getCount();
|
||||
model.addAttribute("commentCount", commentCount);
|
||||
|
||||
//查询最新的文章
|
||||
List<Post> postsLatest = postService.findPostLatest();
|
||||
final List<Post> postsLatest = postService.findPostLatest();
|
||||
model.addAttribute("postTopFive", postsLatest);
|
||||
|
||||
//查询最新的日志
|
||||
List<Logs> logsLatest = logsService.findLogsLatest();
|
||||
final List<Logs> logsLatest = logsService.findLogsLatest();
|
||||
model.addAttribute("logs", logsLatest);
|
||||
|
||||
//查询最新的评论
|
||||
List<Comment> comments = commentService.findCommentsLatest();
|
||||
final List<Comment> comments = commentService.findCommentsLatest();
|
||||
model.addAttribute("comments", comments);
|
||||
|
||||
//附件数量
|
||||
model.addAttribute("mediaCount", attachmentService.getCount());
|
||||
|
||||
//文章阅读总数
|
||||
Long postViewsSum = postService.getPostViews();
|
||||
final Long postViewsSum = postService.getPostViews();
|
||||
model.addAttribute("postViewsSum", postViewsSum);
|
||||
|
||||
//成立天数
|
||||
Date blogStart = DateUtil.parse(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_START.getProp()));
|
||||
long hadDays = DateUtil.between(blogStart, DateUtil.date(), DateUnit.DAY);
|
||||
model.addAttribute("hadDays",hadDays);
|
||||
final Date blogStart = DateUtil.parse(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_START.getProp()));
|
||||
final long hadDays = DateUtil.between(blogStart, DateUtil.date(), DateUnit.DAY);
|
||||
model.addAttribute("hadDays", hadDays);
|
||||
return "admin/admin_index";
|
||||
}
|
||||
|
||||
|
@ -117,11 +118,12 @@ public class AdminController extends BaseController {
|
|||
* 处理跳转到登录页的请求
|
||||
*
|
||||
* @param session session
|
||||
*
|
||||
* @return 模板路径admin/admin_login
|
||||
*/
|
||||
@GetMapping(value = "/login")
|
||||
public String login(HttpSession session) {
|
||||
User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
|
||||
final User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
|
||||
//如果session存在,跳转到后台首页
|
||||
if (null != user) {
|
||||
return "redirect:/admin";
|
||||
|
@ -135,6 +137,7 @@ public class AdminController extends BaseController {
|
|||
* @param loginName 登录名:邮箱/用户名
|
||||
* @param loginPwd loginPwd 密码
|
||||
* @param session session session
|
||||
*
|
||||
* @return JsonResult JsonResult
|
||||
*/
|
||||
@PostMapping(value = "/getLogin")
|
||||
|
@ -143,13 +146,13 @@ public class AdminController extends BaseController {
|
|||
@ModelAttribute("loginPwd") String loginPwd,
|
||||
HttpSession session) {
|
||||
//已注册账号,单用户,只有一个
|
||||
User aUser = userService.findUser();
|
||||
final User aUser = userService.findUser();
|
||||
//首先判断是否已经被禁用已经是否已经过了10分钟
|
||||
Date loginLast = DateUtil.date();
|
||||
if (null != aUser.getLoginLast()) {
|
||||
loginLast = aUser.getLoginLast();
|
||||
}
|
||||
Long between = DateUtil.between(loginLast, DateUtil.date(), DateUnit.MINUTE);
|
||||
final Long between = DateUtil.between(loginLast, DateUtil.date(), DateUnit.MINUTE);
|
||||
if (StrUtil.equals(aUser.getLoginEnable(), TrueFalseEnum.FALSE.getDesc()) && (between < CommonParamsEnum.TEN.getValue())) {
|
||||
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.login.disabled"));
|
||||
}
|
||||
|
@ -171,13 +174,13 @@ public class AdminController extends BaseController {
|
|||
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.login.success"));
|
||||
} else {
|
||||
//更新失败次数
|
||||
Integer errorCount = userService.updateUserLoginError();
|
||||
final Integer errorCount = userService.updateUserLoginError();
|
||||
//超过五次禁用账户
|
||||
if (errorCount >= CommonParamsEnum.FIVE.getValue()) {
|
||||
userService.updateUserLoginEnable(TrueFalseEnum.FALSE.getDesc());
|
||||
}
|
||||
logsService.save(LogsRecord.LOGIN, LogsRecord.LOGIN_ERROR + "[" + HtmlUtil.escape(loginName) + "," + HtmlUtil.escape(loginPwd) + "]", request);
|
||||
Object[] args = {(5 - errorCount)};
|
||||
final Object[] args = {(5 - errorCount)};
|
||||
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.login.failed", args));
|
||||
}
|
||||
}
|
||||
|
@ -186,11 +189,12 @@ public class AdminController extends BaseController {
|
|||
* 退出登录 销毁session
|
||||
*
|
||||
* @param session session
|
||||
*
|
||||
* @return 重定向到/admin/login
|
||||
*/
|
||||
@GetMapping(value = "/logOut")
|
||||
public String logOut(HttpSession session) {
|
||||
User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
|
||||
final User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
|
||||
session.removeAttribute(HaloConst.USER_SESSION_KEY);
|
||||
logsService.save(LogsRecord.LOGOUT, user.getUserName(), request);
|
||||
log.info("User {} has logged out", user.getUserName());
|
||||
|
@ -203,15 +207,16 @@ public class AdminController extends BaseController {
|
|||
* @param model model model
|
||||
* @param page page 当前页码
|
||||
* @param size size 每页条数
|
||||
*
|
||||
* @return 模板路径admin/widget/_logs-all
|
||||
*/
|
||||
@GetMapping(value = "/logs")
|
||||
public String logs(Model model,
|
||||
@RequestParam(value = "page", defaultValue = "0") Integer page,
|
||||
@RequestParam(value = "size", defaultValue = "10") Integer size) {
|
||||
Sort sort = new Sort(Sort.Direction.DESC, "logId");
|
||||
Pageable pageable = PageRequest.of(page, size, sort);
|
||||
Page<Logs> logs = logsService.findAll(pageable);
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "logId");
|
||||
final Pageable pageable = PageRequest.of(page, size, sort);
|
||||
final Page<Logs> logs = logsService.findAll(pageable);
|
||||
model.addAttribute("logs", logs);
|
||||
return "admin/widget/_logs-all";
|
||||
}
|
||||
|
@ -249,7 +254,7 @@ public class AdminController extends BaseController {
|
|||
@GetMapping(value = "/getToken")
|
||||
@ResponseBody
|
||||
public JsonResult getToken() {
|
||||
String token = (System.currentTimeMillis() + new Random().nextInt(999999999)) + "";
|
||||
final String token = (System.currentTimeMillis() + new Random().nextInt(999999999)) + "";
|
||||
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), SecureUtil.md5(token));
|
||||
}
|
||||
|
||||
|
@ -279,6 +284,7 @@ public class AdminController extends BaseController {
|
|||
*
|
||||
* @param file file
|
||||
* @param request request
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@PostMapping(value = "/tools/markdownImport")
|
||||
|
@ -286,14 +292,14 @@ public class AdminController extends BaseController {
|
|||
public JsonResult markdownImport(@RequestParam("file") MultipartFile file,
|
||||
HttpServletRequest request,
|
||||
HttpSession session) throws IOException {
|
||||
User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
|
||||
String markdown = IoUtil.read(file.getInputStream(), "UTF-8");
|
||||
String content = MarkdownUtils.renderMarkdown(markdown);
|
||||
Map<String, List<String>> frontMatters = MarkdownUtils.getFrontMatter(markdown);
|
||||
Post post = new Post();
|
||||
final User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
|
||||
final String markdown = IoUtil.read(file.getInputStream(), "UTF-8");
|
||||
final String content = MarkdownUtils.renderMarkdown(markdown);
|
||||
final Map<String, List<String>> frontMatters = MarkdownUtils.getFrontMatter(markdown);
|
||||
final Post post = new Post();
|
||||
List<String> elementValue = null;
|
||||
List<Tag> tags = new ArrayList<>();
|
||||
List<Category> categories = new ArrayList<>();
|
||||
final List<Tag> tags = new ArrayList<>();
|
||||
final List<Category> categories = new ArrayList<>();
|
||||
Tag tag = null;
|
||||
Category category = null;
|
||||
if (frontMatters.size() > 0) {
|
||||
|
@ -345,9 +351,9 @@ public class AdminController extends BaseController {
|
|||
if (StrUtil.isNotEmpty(HaloConst.OPTIONS.get(BlogPropertiesEnum.POST_SUMMARY.getProp()))) {
|
||||
postSummary = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.POST_SUMMARY.getProp()));
|
||||
}
|
||||
String summaryText = StrUtil.cleanBlank(HtmlUtil.cleanHtmlTag(post.getPostContent()));
|
||||
final String summaryText = StrUtil.cleanBlank(HtmlUtil.cleanHtmlTag(post.getPostContent()));
|
||||
if (summaryText.length() > postSummary) {
|
||||
String summary = summaryText.substring(0, postSummary);
|
||||
final String summary = summaryText.substring(0, postSummary);
|
||||
post.setPostSummary(summary);
|
||||
} else {
|
||||
post.setPostSummary(summaryText);
|
||||
|
|
|
@ -55,15 +55,16 @@ public class AttachmentController {
|
|||
* 复印件列表
|
||||
*
|
||||
* @param model model
|
||||
*
|
||||
* @return 模板路径admin/admin_attachment
|
||||
*/
|
||||
@GetMapping
|
||||
public String attachments(Model model,
|
||||
@RequestParam(value = "page", defaultValue = "0") Integer page,
|
||||
@RequestParam(value = "size", defaultValue = "18") Integer size) {
|
||||
Sort sort = new Sort(Sort.Direction.DESC, "attachId");
|
||||
Pageable pageable = PageRequest.of(page, size, sort);
|
||||
Page<Attachment> attachments = attachmentService.findAll(pageable);
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "attachId");
|
||||
final Pageable pageable = PageRequest.of(page, size, sort);
|
||||
final Page<Attachment> attachments = attachmentService.findAll(pageable);
|
||||
model.addAttribute("attachments", attachments);
|
||||
return "admin/admin_attachment";
|
||||
}
|
||||
|
@ -73,6 +74,7 @@ public class AttachmentController {
|
|||
*
|
||||
* @param model model
|
||||
* @param page page 当前页码
|
||||
*
|
||||
* @return 模板路径admin/widget/_attachment-select
|
||||
*/
|
||||
@GetMapping(value = "/select")
|
||||
|
@ -80,9 +82,9 @@ public class AttachmentController {
|
|||
@RequestParam(value = "page", defaultValue = "0") Integer page,
|
||||
@RequestParam(value = "id", defaultValue = "none") String id,
|
||||
@RequestParam(value = "type", defaultValue = "normal") String type) {
|
||||
Sort sort = new Sort(Sort.Direction.DESC, "attachId");
|
||||
Pageable pageable = PageRequest.of(page, 18, sort);
|
||||
Page<Attachment> attachments = attachmentService.findAll(pageable);
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "attachId");
|
||||
final Pageable pageable = PageRequest.of(page, 18, sort);
|
||||
final Page<Attachment> attachments = attachmentService.findAll(pageable);
|
||||
model.addAttribute("attachments", attachments);
|
||||
model.addAttribute("id", id);
|
||||
if (StrUtil.equals(type, PostTypeEnum.POST_TYPE_POST.getDesc())) {
|
||||
|
@ -107,16 +109,17 @@ public class AttachmentController {
|
|||
*
|
||||
* @param file file
|
||||
* @param request request
|
||||
*
|
||||
* @return Map
|
||||
*/
|
||||
@PostMapping(value = "/upload", produces = {"application/json;charset=UTF-8"})
|
||||
@ResponseBody
|
||||
public Map<String, Object> upload(@RequestParam("file") MultipartFile file,
|
||||
HttpServletRequest request) {
|
||||
Map<String, Object> result = new HashMap<>(3);
|
||||
final Map<String, Object> result = new HashMap<>(3);
|
||||
if (!file.isEmpty()) {
|
||||
try {
|
||||
Map<String, String> resultMap = attachmentService.upload(file, request);
|
||||
final Map<String, String> resultMap = attachmentService.upload(file, request);
|
||||
if (resultMap == null || resultMap.isEmpty()) {
|
||||
log.error("File upload failed");
|
||||
result.put("success", ResultCodeEnum.FAIL.getCode());
|
||||
|
@ -157,12 +160,13 @@ public class AttachmentController {
|
|||
*
|
||||
* @param model model
|
||||
* @param attachId 附件编号
|
||||
*
|
||||
* @return 模板路径admin/widget/_attachment-detail
|
||||
*/
|
||||
@GetMapping(value = "/attachment")
|
||||
public String attachmentDetail(Model model, @RequestParam("attachId") Long attachId) {
|
||||
Optional<Attachment> attachment = attachmentService.findByAttachId(attachId);
|
||||
model.addAttribute("attachment", attachment.get());
|
||||
final Optional<Attachment> attachment = attachmentService.findByAttachId(attachId);
|
||||
model.addAttribute("attachment", attachment.orElse(new Attachment()));
|
||||
return "admin/widget/_attachment-detail";
|
||||
}
|
||||
|
||||
|
@ -171,6 +175,7 @@ public class AttachmentController {
|
|||
*
|
||||
* @param attachId 附件编号
|
||||
* @param request request
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/remove")
|
||||
|
|
|
@ -57,6 +57,7 @@ public class BackupController {
|
|||
* 渲染备份页面
|
||||
*
|
||||
* @param model model
|
||||
*
|
||||
* @return 模板路径admin/admin_backup
|
||||
*/
|
||||
@GetMapping
|
||||
|
@ -80,6 +81,7 @@ public class BackupController {
|
|||
* 执行备份
|
||||
*
|
||||
* @param type 备份类型
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "doBackup")
|
||||
|
@ -106,8 +108,8 @@ public class BackupController {
|
|||
if (HaloUtils.getBackUps(BackupTypeEnum.DATABASES.getDesc()).size() > CommonParamsEnum.TEN.getValue()) {
|
||||
FileUtil.del(System.getProperties().getProperty("user.home") + "/halo/backup/databases/");
|
||||
}
|
||||
String srcPath = System.getProperties().getProperty("user.home") + "/halo/";
|
||||
String distName = "databases_backup_" + DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");
|
||||
final String srcPath = System.getProperties().getProperty("user.home") + "/halo/";
|
||||
final String distName = "databases_backup_" + DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");
|
||||
//压缩文件
|
||||
ZipUtil.zip(srcPath + "halo.mv.db", System.getProperties().getProperty("user.home") + "/halo/backup/databases/" + distName + ".zip");
|
||||
log.info("Current time: {}, database backup was performed.", DateUtil.now());
|
||||
|
@ -128,9 +130,9 @@ public class BackupController {
|
|||
if (HaloUtils.getBackUps(BackupTypeEnum.RESOURCES.getDesc()).size() > CommonParamsEnum.TEN.getValue()) {
|
||||
FileUtil.del(System.getProperties().getProperty("user.home") + "/halo/backup/resources/");
|
||||
}
|
||||
File path = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
String srcPath = path.getAbsolutePath();
|
||||
String distName = "resources_backup_" + DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");
|
||||
final File path = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
final String srcPath = path.getAbsolutePath();
|
||||
final String distName = "resources_backup_" + DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");
|
||||
//执行打包
|
||||
ZipUtil.zip(srcPath, System.getProperties().getProperty("user.home") + "/halo/backup/resources/" + distName + ".zip");
|
||||
log.info("Current time: {}, the resource file backup was performed.", DateUtil.now());
|
||||
|
@ -147,15 +149,15 @@ public class BackupController {
|
|||
* @return JsonResult
|
||||
*/
|
||||
public JsonResult backupPosts() {
|
||||
List<Post> posts = postService.findAll(PostTypeEnum.POST_TYPE_POST.getDesc());
|
||||
final List<Post> posts = postService.findAll(PostTypeEnum.POST_TYPE_POST.getDesc());
|
||||
posts.addAll(postService.findAll(PostTypeEnum.POST_TYPE_PAGE.getDesc()));
|
||||
try {
|
||||
if (HaloUtils.getBackUps(BackupTypeEnum.POSTS.getDesc()).size() > CommonParamsEnum.TEN.getValue()) {
|
||||
FileUtil.del(System.getProperties().getProperty("user.home") + "/halo/backup/posts/");
|
||||
}
|
||||
//打包好的文件名
|
||||
String distName = "posts_backup_" + DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");
|
||||
String srcPath = System.getProperties().getProperty("user.home") + "/halo/backup/posts/" + distName;
|
||||
final String distName = "posts_backup_" + DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss");
|
||||
final String srcPath = System.getProperties().getProperty("user.home") + "/halo/backup/posts/" + distName;
|
||||
for (Post post : posts) {
|
||||
HaloUtils.postToFile(post.getPostContentMd(), srcPath, post.getPostTitle() + ".md");
|
||||
}
|
||||
|
@ -175,13 +177,14 @@ public class BackupController {
|
|||
*
|
||||
* @param fileName 文件名
|
||||
* @param type 备份类型
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "delBackup")
|
||||
@ResponseBody
|
||||
public JsonResult delBackup(@RequestParam("fileName") String fileName,
|
||||
@RequestParam("type") String type) {
|
||||
String srcPath = System.getProperties().getProperty("user.home") + "/halo/backup/" + type + "/" + fileName;
|
||||
final String srcPath = System.getProperties().getProperty("user.home") + "/halo/backup/" + type + "/" + fileName;
|
||||
try {
|
||||
FileUtil.del(srcPath);
|
||||
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.common.delete-success"));
|
||||
|
@ -195,6 +198,7 @@ public class BackupController {
|
|||
*
|
||||
* @param fileName 文件名
|
||||
* @param type 备份类型
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "sendToEmail")
|
||||
|
@ -202,9 +206,9 @@ public class BackupController {
|
|||
public JsonResult sendToEmail(@RequestParam("fileName") String fileName,
|
||||
@RequestParam("type") String type,
|
||||
HttpSession session) {
|
||||
String srcPath = System.getProperties().getProperty("user.home") + "/halo/backup/" + type + "/" + fileName;
|
||||
User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
|
||||
if (null == user.getUserEmail() || StrUtil.equals(user.getUserEmail(), "")) {
|
||||
final String srcPath = System.getProperties().getProperty("user.home") + "/halo/backup/" + type + "/" + fileName;
|
||||
final User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
|
||||
if (null == user.getUserEmail() || StrUtil.isEmpty(user.getUserEmail())) {
|
||||
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.backup.no-email"));
|
||||
}
|
||||
if (StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.FALSE.getDesc())) {
|
||||
|
@ -228,8 +232,8 @@ public class BackupController {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
File file = new File(srcPath);
|
||||
Map<String, Object> content = new HashMap<>(3);
|
||||
final File file = new File(srcPath);
|
||||
final Map<String, Object> content = new HashMap<>(3);
|
||||
try {
|
||||
content.put("fileName", file.getName());
|
||||
content.put("createAt", HaloUtils.getCreateTime(srcPath));
|
||||
|
|
|
@ -104,7 +104,7 @@ public class CategoryController {
|
|||
*/
|
||||
@GetMapping(value = "/edit")
|
||||
public String toEditCategory(Model model, @RequestParam("cateId") Long cateId) {
|
||||
Optional<Category> category = categoryService.findByCateId(cateId);
|
||||
final Optional<Category> category = categoryService.findByCateId(cateId);
|
||||
model.addAttribute("updateCategory", category.orElse(new Category()));
|
||||
return "admin/admin_category";
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ public class CommentController extends BaseController {
|
|||
* @param status status 评论状态
|
||||
* @param page page 当前页码
|
||||
* @param size size 每页显示条数
|
||||
*
|
||||
* @return 模板路径admin/admin_comment
|
||||
*/
|
||||
@GetMapping
|
||||
|
@ -69,9 +70,9 @@ public class CommentController extends BaseController {
|
|||
@RequestParam(value = "status", defaultValue = "0") Integer status,
|
||||
@RequestParam(value = "page", defaultValue = "0") Integer page,
|
||||
@RequestParam(value = "size", defaultValue = "10") Integer size) {
|
||||
Sort sort = new Sort(Sort.Direction.DESC, "commentDate");
|
||||
Pageable pageable = PageRequest.of(page, size, sort);
|
||||
Page<Comment> comments = commentService.findAll(status,pageable);
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "commentDate");
|
||||
final Pageable pageable = PageRequest.of(page, size, sort);
|
||||
final Page<Comment> comments = commentService.findAll(status, pageable);
|
||||
model.addAttribute("comments", comments);
|
||||
model.addAttribute("publicCount", commentService.getCountByStatus(CommentStatusEnum.PUBLISHED.getCode()));
|
||||
model.addAttribute("checkCount", commentService.getCountByStatus(CommentStatusEnum.CHECKING.getCode()));
|
||||
|
@ -85,6 +86,7 @@ public class CommentController extends BaseController {
|
|||
*
|
||||
* @param commentId 评论编号
|
||||
* @param status 评论状态
|
||||
*
|
||||
* @return 重定向到/admin/comments
|
||||
*/
|
||||
@GetMapping(value = "/throw")
|
||||
|
@ -105,15 +107,16 @@ public class CommentController extends BaseController {
|
|||
* @param commentId 评论编号
|
||||
* @param status 评论状态
|
||||
* @param session session
|
||||
*
|
||||
* @return 重定向到/admin/comments
|
||||
*/
|
||||
@GetMapping(value = "/revert")
|
||||
public String moveToPublish(@RequestParam("commentId") Long commentId,
|
||||
@RequestParam("status") Integer status,
|
||||
HttpSession session) {
|
||||
Comment comment = commentService.updateCommentStatus(commentId, CommentStatusEnum.PUBLISHED.getCode());
|
||||
Post post = comment.getPost();
|
||||
User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
|
||||
final Comment comment = commentService.updateCommentStatus(commentId, CommentStatusEnum.PUBLISHED.getCode());
|
||||
final Post post = comment.getPost();
|
||||
final User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
|
||||
|
||||
//判断是否启用邮件服务
|
||||
new NoticeToAuthor(comment, post, user, status).start();
|
||||
|
@ -126,6 +129,7 @@ public class CommentController extends BaseController {
|
|||
* @param commentId commentId 评论编号
|
||||
* @param status status 评论状态
|
||||
* @param page 当前页码
|
||||
*
|
||||
* @return string 重定向到/admin/comments
|
||||
*/
|
||||
@GetMapping(value = "/remove")
|
||||
|
@ -146,6 +150,7 @@ public class CommentController extends BaseController {
|
|||
*
|
||||
* @param commentId 被回复的评论
|
||||
* @param commentContent 回复的内容
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@PostMapping(value = "/reply")
|
||||
|
@ -157,20 +162,20 @@ public class CommentController extends BaseController {
|
|||
HttpServletRequest request,
|
||||
HttpSession session) {
|
||||
try {
|
||||
Post post = postService.findByPostId(postId).orElse(new Post());
|
||||
final Post post = postService.findByPostId(postId).orElse(new Post());
|
||||
|
||||
//博主信息
|
||||
User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
|
||||
final User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
|
||||
|
||||
//被回复的评论
|
||||
Comment lastComment = commentService.findCommentById(commentId).orElse(new Comment());
|
||||
final Comment lastComment = commentService.findCommentById(commentId).orElse(new Comment());
|
||||
|
||||
//修改被回复的评论的状态
|
||||
lastComment.setCommentStatus(CommentStatusEnum.PUBLISHED.getCode());
|
||||
commentService.save(lastComment);
|
||||
|
||||
//保存评论
|
||||
Comment comment = new Comment();
|
||||
final Comment comment = new Comment();
|
||||
comment.setPost(post);
|
||||
comment.setCommentAuthor(user.getUserDisplayName());
|
||||
comment.setCommentAuthorEmail(user.getUserEmail());
|
||||
|
@ -179,7 +184,7 @@ public class CommentController extends BaseController {
|
|||
comment.setCommentAuthorAvatarMd5(SecureUtil.md5(user.getUserEmail()));
|
||||
comment.setCommentDate(DateUtil.date());
|
||||
|
||||
StrBuilder buildContent = new StrBuilder("<a href='#comment-id-");
|
||||
final StrBuilder buildContent = new StrBuilder("<a href='#comment-id-");
|
||||
buildContent.append(lastComment.getCommentId());
|
||||
buildContent.append("'>@");
|
||||
buildContent.append(lastComment.getCommentAuthor());
|
||||
|
@ -225,12 +230,12 @@ public class CommentController extends BaseController {
|
|||
public void run() {
|
||||
if (StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.COMMENT_REPLY_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) {
|
||||
if (Validator.isEmail(lastComment.getCommentAuthorEmail())) {
|
||||
Map<String, Object> map = new HashMap<>(8);
|
||||
final Map<String, Object> map = new HashMap<>(8);
|
||||
map.put("blogTitle", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp()));
|
||||
map.put("commentAuthor", lastComment.getCommentAuthor());
|
||||
map.put("pageName", lastComment.getPost().getPostTitle());
|
||||
|
||||
StrBuilder pageUrl = new StrBuilder(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
|
||||
final StrBuilder pageUrl = new StrBuilder(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
|
||||
if (StrUtil.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) {
|
||||
pageUrl.append("/archives/");
|
||||
} else {
|
||||
|
@ -240,7 +245,7 @@ public class CommentController extends BaseController {
|
|||
pageUrl.append("#comment-id-");
|
||||
pageUrl.append(comment.getCommentId());
|
||||
|
||||
map.put("pageUrl",pageUrl.toString());
|
||||
map.put("pageUrl", pageUrl.toString());
|
||||
map.put("commentContent", lastComment.getCommentContent());
|
||||
map.put("replyAuthor", user.getUserDisplayName());
|
||||
map.put("replyContent", commentContent);
|
||||
|
@ -274,9 +279,9 @@ public class CommentController extends BaseController {
|
|||
if (StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.COMMENT_REPLY_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) {
|
||||
try {
|
||||
if (status == 1 && Validator.isEmail(comment.getCommentAuthorEmail())) {
|
||||
Map<String, Object> map = new HashMap<>(6);
|
||||
final Map<String, Object> map = new HashMap<>(6);
|
||||
|
||||
StrBuilder pageUrl = new StrBuilder(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
|
||||
final StrBuilder pageUrl = new StrBuilder(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
|
||||
if (StrUtil.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) {
|
||||
pageUrl.append("/archives/");
|
||||
} else {
|
||||
|
@ -286,7 +291,7 @@ public class CommentController extends BaseController {
|
|||
pageUrl.append("#comment-id-");
|
||||
pageUrl.append(comment.getCommentId());
|
||||
|
||||
map.put("pageUrl",pageUrl.toString());
|
||||
map.put("pageUrl", pageUrl.toString());
|
||||
map.put("pageName", post.getPostTitle());
|
||||
map.put("commentContent", comment.getCommentContent());
|
||||
map.put("blogUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
|
||||
|
|
|
@ -75,7 +75,7 @@ public class MenuController {
|
|||
*/
|
||||
@GetMapping(value = "/edit")
|
||||
public String updateMenu(@RequestParam("menuId") Long menuId, Model model) {
|
||||
Menu menu = menuService.findByMenuId(menuId).orElse(new Menu());
|
||||
final Menu menu = menuService.findByMenuId(menuId).orElse(new Menu());
|
||||
model.addAttribute("updateMenu", menu);
|
||||
return "/admin/admin_menu";
|
||||
}
|
||||
|
|
|
@ -10,7 +10,9 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
@ -49,17 +51,19 @@ public class OptionController {
|
|||
* 保存设置选项
|
||||
*
|
||||
* @param options options
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@PostMapping(value = "/save")
|
||||
@ResponseBody
|
||||
public JsonResult saveOptions(@RequestParam Map<String, String> options) {
|
||||
public JsonResult saveOptions(@RequestParam Map<String, String> options, HttpSession session) {
|
||||
try {
|
||||
optionsService.saveOptions(options);
|
||||
//刷新options
|
||||
configuration.setSharedVariable("options", optionsService.findAllOptions());
|
||||
HaloConst.OPTIONS.clear();
|
||||
HaloConst.OPTIONS = optionsService.findAllOptions();
|
||||
session.removeAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME);
|
||||
log.info("List of saved options: " + options);
|
||||
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.common.save-success"));
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -77,7 +77,7 @@ public class PageController {
|
|||
*/
|
||||
@GetMapping
|
||||
public String pages(Model model) {
|
||||
List<Post> posts = postService.findAll(PostTypeEnum.POST_TYPE_PAGE.getDesc());
|
||||
final List<Post> posts = postService.findAll(PostTypeEnum.POST_TYPE_PAGE.getDesc());
|
||||
model.addAttribute("pages", posts);
|
||||
return "admin/admin_page";
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ public class PageController {
|
|||
*/
|
||||
@GetMapping(value = "/links/edit")
|
||||
public String toEditLink(Model model, @RequestParam("linkId") Long linkId) {
|
||||
Optional<Link> link = linkService.findByLinkId(linkId);
|
||||
final Optional<Link> link = linkService.findByLinkId(linkId);
|
||||
model.addAttribute("updateLink", link.orElse(new Link()));
|
||||
return "admin/admin_page_link";
|
||||
}
|
||||
|
@ -159,9 +159,9 @@ public class PageController {
|
|||
public String gallery(Model model,
|
||||
@RequestParam(value = "page", defaultValue = "0") Integer page,
|
||||
@RequestParam(value = "size", defaultValue = "18") Integer size) {
|
||||
Sort sort = new Sort(Sort.Direction.DESC, "galleryId");
|
||||
Pageable pageable = PageRequest.of(page, size, sort);
|
||||
Page<Gallery> galleries = galleryService.findAll(pageable);
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "galleryId");
|
||||
final Pageable pageable = PageRequest.of(page, size, sort);
|
||||
final Page<Gallery> galleries = galleryService.findAll(pageable);
|
||||
model.addAttribute("galleries", galleries);
|
||||
return "admin/admin_page_gallery";
|
||||
}
|
||||
|
@ -196,8 +196,8 @@ public class PageController {
|
|||
*/
|
||||
@GetMapping(value = "/gallery")
|
||||
public String gallery(Model model, @RequestParam("galleryId") Long galleryId) {
|
||||
Optional<Gallery> gallery = galleryService.findByGalleryId(galleryId);
|
||||
model.addAttribute("gallery", gallery.get());
|
||||
final Optional<Gallery> gallery = galleryService.findByGalleryId(galleryId);
|
||||
model.addAttribute("gallery", gallery.orElse(new Gallery()));
|
||||
return "admin/widget/_gallery-detail";
|
||||
}
|
||||
|
||||
|
@ -229,7 +229,7 @@ public class PageController {
|
|||
*/
|
||||
@GetMapping(value = "/new")
|
||||
public String newPage(Model model) {
|
||||
List<String> customTpls = HaloUtils.getCustomTpl(HaloConst.OPTIONS.get(BlogPropertiesEnum.THEME.getProp()));
|
||||
final List<String> customTpls = HaloUtils.getCustomTpl(HaloConst.OPTIONS.get(BlogPropertiesEnum.THEME.getProp()));
|
||||
model.addAttribute("customTpls", customTpls);
|
||||
return "admin/admin_page_md_editor";
|
||||
}
|
||||
|
@ -246,11 +246,11 @@ public class PageController {
|
|||
String msg = localeMessageUtil.getMessage("code.admin.common.save-success");
|
||||
try {
|
||||
//发表用户
|
||||
User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
|
||||
final User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
|
||||
post.setUser(user);
|
||||
post.setPostType(PostTypeEnum.POST_TYPE_PAGE.getDesc());
|
||||
if (null != post.getPostId()) {
|
||||
Post oldPost = postService.findByPostId(post.getPostId()).get();
|
||||
final Post oldPost = postService.findByPostId(post.getPostId()).get();
|
||||
if (null == post.getPostDate()) {
|
||||
post.setPostDate(DateUtil.date());
|
||||
}
|
||||
|
@ -284,8 +284,8 @@ public class PageController {
|
|||
*/
|
||||
@GetMapping(value = "/edit")
|
||||
public String editPage(@RequestParam("pageId") Long pageId, Model model) {
|
||||
Optional<Post> post = postService.findByPostId(pageId);
|
||||
List<String> customTpls = HaloUtils.getCustomTpl(HaloConst.OPTIONS.get(BlogPropertiesEnum.THEME.getProp()));
|
||||
final Optional<Post> post = postService.findByPostId(pageId);
|
||||
final List<String> customTpls = HaloUtils.getCustomTpl(HaloConst.OPTIONS.get(BlogPropertiesEnum.THEME.getProp()));
|
||||
model.addAttribute("post", post.orElse(new Post()));
|
||||
model.addAttribute("customTpls", customTpls);
|
||||
return "admin/admin_page_md_editor";
|
||||
|
@ -301,7 +301,7 @@ public class PageController {
|
|||
@GetMapping(value = "/checkUrl")
|
||||
@ResponseBody
|
||||
public JsonResult checkUrlExists(@RequestParam("postUrl") String postUrl) {
|
||||
Post post = postService.findByPostUrl(postUrl, PostTypeEnum.POST_TYPE_PAGE.getDesc());
|
||||
final Post post = postService.findByPostUrl(postUrl, PostTypeEnum.POST_TYPE_PAGE.getDesc());
|
||||
if (null != post) {
|
||||
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.common.url-is-exists"));
|
||||
}
|
||||
|
|
|
@ -92,9 +92,9 @@ public class PostController extends BaseController {
|
|||
@RequestParam(value = "status", defaultValue = "0") Integer status,
|
||||
@RequestParam(value = "page", defaultValue = "0") Integer page,
|
||||
@RequestParam(value = "size", defaultValue = "10") Integer size) {
|
||||
Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
Pageable pageable = PageRequest.of(page, size, sort);
|
||||
Page<Post> posts = postService.findPostByStatus(status, PostTypeEnum.POST_TYPE_POST.getDesc(), pageable);
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
final Pageable pageable = PageRequest.of(page, size, sort);
|
||||
final Page<Post> posts = postService.findPostByStatus(status, PostTypeEnum.POST_TYPE_POST.getDesc(), pageable);
|
||||
model.addAttribute("posts", posts);
|
||||
model.addAttribute("publishCount", postService.getCountByStatus(PostStatusEnum.PUBLISHED.getCode()));
|
||||
model.addAttribute("draftCount", postService.getCountByStatus(PostStatusEnum.DRAFT.getCode()));
|
||||
|
@ -119,8 +119,8 @@ public class PostController extends BaseController {
|
|||
@RequestParam(value = "size", defaultValue = "10") Integer size) {
|
||||
try {
|
||||
//排序规则
|
||||
Sort sort = new Sort(Sort.Direction.DESC, "postId");
|
||||
Pageable pageable = PageRequest.of(page, size, sort);
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "postId");
|
||||
final Pageable pageable = PageRequest.of(page, size, sort);
|
||||
model.addAttribute("posts", postService.searchPosts(keyword, pageable));
|
||||
} catch (Exception e) {
|
||||
log.error("未知错误:{}", e.getMessage());
|
||||
|
@ -137,7 +137,7 @@ public class PostController extends BaseController {
|
|||
*/
|
||||
@GetMapping(value = "/view")
|
||||
public String viewPost(@RequestParam("postId") Long postId, Model model) {
|
||||
Optional<Post> post = postService.findByPostId(postId);
|
||||
final Optional<Post> post = postService.findByPostId(postId);
|
||||
model.addAttribute("post", post.orElse(new Post()));
|
||||
return this.render("post");
|
||||
}
|
||||
|
@ -161,8 +161,8 @@ public class PostController extends BaseController {
|
|||
*/
|
||||
@GetMapping(value = "/edit")
|
||||
public String editPost(@RequestParam("postId") Long postId, Model model) {
|
||||
Optional<Post> post = postService.findByPostId(postId);
|
||||
model.addAttribute("post", post.get());
|
||||
final Optional<Post> post = postService.findByPostId(postId);
|
||||
model.addAttribute("post", post.orElse(new Post()));
|
||||
return "admin/admin_post_edit";
|
||||
}
|
||||
|
||||
|
@ -180,7 +180,7 @@ public class PostController extends BaseController {
|
|||
@RequestParam("cateList") List<String> cateList,
|
||||
@RequestParam("tagList") String tagList,
|
||||
HttpSession session) {
|
||||
User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
|
||||
final User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
|
||||
try {
|
||||
post.setPostContent(MarkdownUtils.renderMarkdown(post.getPostContentMd()));
|
||||
//摘要字数
|
||||
|
@ -189,9 +189,9 @@ public class PostController extends BaseController {
|
|||
postSummary = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.POST_SUMMARY.getProp()));
|
||||
}
|
||||
//设置文章摘要
|
||||
String summaryText = StrUtil.cleanBlank(HtmlUtil.cleanHtmlTag(post.getPostContent()));
|
||||
final String summaryText = StrUtil.cleanBlank(HtmlUtil.cleanHtmlTag(post.getPostContent()));
|
||||
if (summaryText.length() > postSummary) {
|
||||
String summary = summaryText.substring(0, postSummary);
|
||||
final String summary = summaryText.substring(0, postSummary);
|
||||
post.setPostSummary(summary);
|
||||
} else {
|
||||
post.setPostSummary(summaryText);
|
||||
|
@ -231,7 +231,7 @@ public class PostController extends BaseController {
|
|||
@RequestParam("cateList") List<String> cateList,
|
||||
@RequestParam("tagList") String tagList) {
|
||||
//old data
|
||||
Post oldPost = postService.findByPostId(post.getPostId()).orElse(new Post());
|
||||
final Post oldPost = postService.findByPostId(post.getPostId()).orElse(new Post());
|
||||
post.setPostUpdate(new Date());
|
||||
post.setPostViews(oldPost.getPostViews());
|
||||
post.setPostContent(MarkdownUtils.renderMarkdown(post.getPostContentMd()));
|
||||
|
@ -245,9 +245,9 @@ public class PostController extends BaseController {
|
|||
postSummary = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.POST_SUMMARY.getProp()));
|
||||
}
|
||||
//设置文章摘要
|
||||
String summaryText = StrUtil.cleanBlank(HtmlUtil.cleanHtmlTag(post.getPostContent()));
|
||||
final String summaryText = StrUtil.cleanBlank(HtmlUtil.cleanHtmlTag(post.getPostContent()));
|
||||
if (summaryText.length() > postSummary) {
|
||||
String summary = summaryText.substring(0, postSummary);
|
||||
final String summary = summaryText.substring(0, postSummary);
|
||||
post.setPostSummary(summary);
|
||||
} else {
|
||||
post.setPostSummary(summaryText);
|
||||
|
@ -309,7 +309,7 @@ public class PostController extends BaseController {
|
|||
@GetMapping(value = "/remove")
|
||||
public String removePost(@RequestParam("postId") Long postId, @RequestParam("postType") String postType) {
|
||||
try {
|
||||
Optional<Post> post = postService.findByPostId(postId);
|
||||
final Optional<Post> post = postService.findByPostId(postId);
|
||||
postService.remove(postId);
|
||||
logsService.save(LogsRecord.REMOVE_POST, post.get().getPostTitle(), request);
|
||||
} catch (Exception e) {
|
||||
|
@ -350,7 +350,7 @@ public class PostController extends BaseController {
|
|||
@ResponseBody
|
||||
public JsonResult checkUrlExists(@RequestParam("postUrl") String postUrl) {
|
||||
postUrl = urlFilter(postUrl);
|
||||
Post post = postService.findByPostUrl(postUrl, PostTypeEnum.POST_TYPE_POST.getDesc());
|
||||
final Post post = postService.findByPostUrl(postUrl, PostTypeEnum.POST_TYPE_POST.getDesc());
|
||||
if (null != post) {
|
||||
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.common.url-is-exists"));
|
||||
}
|
||||
|
@ -369,16 +369,16 @@ public class PostController extends BaseController {
|
|||
if (StrUtil.isBlank(baiduToken)) {
|
||||
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.post.no-baidu-token"));
|
||||
}
|
||||
String blogUrl = HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp());
|
||||
List<Post> posts = postService.findAll(PostTypeEnum.POST_TYPE_POST.getDesc());
|
||||
StringBuilder urls = new StringBuilder();
|
||||
final String blogUrl = HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp());
|
||||
final List<Post> posts = postService.findAll(PostTypeEnum.POST_TYPE_POST.getDesc());
|
||||
final StringBuilder urls = new StringBuilder();
|
||||
for (Post post : posts) {
|
||||
urls.append(blogUrl);
|
||||
urls.append("/archives/");
|
||||
urls.append(post.getPostUrl());
|
||||
urls.append("\n");
|
||||
}
|
||||
String result = HaloUtils.baiduPost(blogUrl, baiduToken, urls.toString());
|
||||
final String result = HaloUtils.baiduPost(blogUrl, baiduToken, urls.toString());
|
||||
if (StrUtil.isEmpty(result)) {
|
||||
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.post.push-to-baidu-failed"));
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import cc.ryanc.halo.web.controller.core.BaseController;
|
|||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.file.FileReader;
|
||||
import cn.hutool.core.io.file.FileWriter;
|
||||
import cn.hutool.core.text.StrBuilder;
|
||||
import cn.hutool.core.util.RuntimeUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.ZipUtil;
|
||||
|
@ -63,6 +64,7 @@ public class ThemeController extends BaseController {
|
|||
* 渲染主题设置页面
|
||||
*
|
||||
* @param model model
|
||||
*
|
||||
* @return 模板路径admin/admin_theme
|
||||
*/
|
||||
@GetMapping
|
||||
|
@ -79,6 +81,7 @@ public class ThemeController extends BaseController {
|
|||
*
|
||||
* @param siteTheme 主题名称
|
||||
* @param request request
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/set")
|
||||
|
@ -108,6 +111,7 @@ public class ThemeController extends BaseController {
|
|||
* 上传主题
|
||||
*
|
||||
* @param file 文件
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@RequestMapping(value = "/upload", method = RequestMethod.POST)
|
||||
|
@ -117,8 +121,8 @@ public class ThemeController extends BaseController {
|
|||
try {
|
||||
if (!file.isEmpty()) {
|
||||
//获取项目根路径
|
||||
File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
File themePath = new File(basePath.getAbsolutePath(), new StringBuffer("templates/themes/").append(file.getOriginalFilename()).toString());
|
||||
final File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
final File themePath = new File(basePath.getAbsolutePath(), new StringBuffer("templates/themes/").append(file.getOriginalFilename()).toString());
|
||||
file.transferTo(themePath);
|
||||
log.info("Upload topic success, path is " + themePath.getAbsolutePath());
|
||||
logsService.save(LogsRecord.UPLOAD_THEME, file.getOriginalFilename(), request);
|
||||
|
@ -141,13 +145,14 @@ public class ThemeController extends BaseController {
|
|||
* 删除主题
|
||||
*
|
||||
* @param themeName 主题文件夹名
|
||||
*
|
||||
* @return string 重定向到/admin/themes
|
||||
*/
|
||||
@GetMapping(value = "/remove")
|
||||
public String removeTheme(@RequestParam("themeName") String themeName) {
|
||||
try {
|
||||
File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
File themePath = new File(basePath.getAbsolutePath(), "templates/themes/" + themeName);
|
||||
final File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
final File themePath = new File(basePath.getAbsolutePath(), "templates/themes/" + themeName);
|
||||
FileUtil.del(themePath);
|
||||
HaloConst.THEMES.clear();
|
||||
HaloConst.THEMES = HaloUtils.getThemes();
|
||||
|
@ -172,6 +177,7 @@ public class ThemeController extends BaseController {
|
|||
*
|
||||
* @param remoteAddr 远程地址
|
||||
* @param themeName 主题名称
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@PostMapping(value = "/clone")
|
||||
|
@ -182,9 +188,9 @@ public class ThemeController extends BaseController {
|
|||
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.common.info-no-complete"));
|
||||
}
|
||||
try {
|
||||
File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
File themePath = new File(basePath.getAbsolutePath(), "templates/themes");
|
||||
String cmdResult = RuntimeUtil.execForStr("git clone " + remoteAddr + " " + themePath.getAbsolutePath() + "/" + themeName);
|
||||
final File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
final File themePath = new File(basePath.getAbsolutePath(), "templates/themes");
|
||||
final String cmdResult = RuntimeUtil.execForStr("git clone " + remoteAddr + " " + themePath.getAbsolutePath() + "/" + themeName);
|
||||
if (NOT_FOUND_GIT.equals(cmdResult)) {
|
||||
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.theme.no-git"));
|
||||
}
|
||||
|
@ -201,15 +207,16 @@ public class ThemeController extends BaseController {
|
|||
* 更新主题
|
||||
*
|
||||
* @param themeName 主题名
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/pull")
|
||||
@ResponseBody
|
||||
public JsonResult pullFromRemote(@RequestParam(value = "themeName") String themeName) {
|
||||
try {
|
||||
File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
File themePath = new File(basePath.getAbsolutePath(), "templates/themes");
|
||||
String cmdResult = RuntimeUtil.execForStr("cd " + themePath.getAbsolutePath() + "/" + themeName + " && git pull");
|
||||
final File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
final File themePath = new File(basePath.getAbsolutePath(), "templates/themes");
|
||||
final String cmdResult = RuntimeUtil.execForStr("cd " + themePath.getAbsolutePath() + "/" + themeName, "git pull");
|
||||
if (NOT_FOUND_GIT.equals(cmdResult)) {
|
||||
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.theme.no-git"));
|
||||
}
|
||||
|
@ -244,11 +251,12 @@ public class ThemeController extends BaseController {
|
|||
* 编辑主题
|
||||
*
|
||||
* @param model model
|
||||
*
|
||||
* @return 模板路径admin/admin_theme-editor
|
||||
*/
|
||||
@GetMapping(value = "/editor")
|
||||
public String editor(Model model) {
|
||||
List<String> tpls = HaloUtils.getTplName(BaseController.THEME);
|
||||
final List<String> tpls = HaloUtils.getTplName(BaseController.THEME);
|
||||
model.addAttribute("tpls", tpls);
|
||||
return "admin/admin_theme-editor";
|
||||
}
|
||||
|
@ -257,6 +265,7 @@ public class ThemeController extends BaseController {
|
|||
* 获取模板文件内容
|
||||
*
|
||||
* @param tplName 模板文件名
|
||||
*
|
||||
* @return 模板内容
|
||||
*/
|
||||
@GetMapping(value = "/getTpl", produces = "text/text;charset=UTF-8")
|
||||
|
@ -265,10 +274,14 @@ public class ThemeController extends BaseController {
|
|||
String tplContent = "";
|
||||
try {
|
||||
//获取项目根路径
|
||||
File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
final File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
//获取主题路径
|
||||
File themesPath = new File(basePath.getAbsolutePath(), new StringBuffer("templates/themes/").append(BaseController.THEME).append("/").append(tplName).toString());
|
||||
FileReader fileReader = new FileReader(themesPath);
|
||||
final StrBuilder themePath = new StrBuilder("templates/themes/");
|
||||
themePath.append(BaseController.THEME);
|
||||
themePath.append("/");
|
||||
themePath.append(tplName);
|
||||
final File themesPath = new File(basePath.getAbsolutePath(), themePath.toString());
|
||||
final FileReader fileReader = new FileReader(themesPath);
|
||||
tplContent = fileReader.readString();
|
||||
} catch (Exception e) {
|
||||
log.error("Get template file error: {}", e.getMessage());
|
||||
|
@ -281,6 +294,7 @@ public class ThemeController extends BaseController {
|
|||
*
|
||||
* @param tplName 模板名称
|
||||
* @param tplContent 模板内容
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@PostMapping(value = "/editor/save")
|
||||
|
@ -292,10 +306,14 @@ public class ThemeController extends BaseController {
|
|||
}
|
||||
try {
|
||||
//获取项目根路径
|
||||
File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
final File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
//获取主题路径
|
||||
File tplPath = new File(basePath.getAbsolutePath(), new StringBuffer("templates/themes/").append(BaseController.THEME).append("/").append(tplName).toString());
|
||||
FileWriter fileWriter = new FileWriter(tplPath);
|
||||
final StrBuilder themePath = new StrBuilder("templates/themes/");
|
||||
themePath.append(BaseController.THEME);
|
||||
themePath.append("/");
|
||||
themePath.append(tplName);
|
||||
final File tplPath = new File(basePath.getAbsolutePath(), themePath.toString());
|
||||
final FileWriter fileWriter = new FileWriter(tplPath);
|
||||
fileWriter.write(tplContent);
|
||||
} catch (Exception e) {
|
||||
log.error("Template save failed: {}", e.getMessage());
|
||||
|
|
|
@ -92,7 +92,7 @@ public class UserController {
|
|||
@ModelAttribute("userId") Long userId,
|
||||
HttpSession session) {
|
||||
try {
|
||||
User user = userService.findByUserIdAndUserPass(userId, SecureUtil.md5(beforePass));
|
||||
final User user = userService.findByUserIdAndUserPass(userId, SecureUtil.md5(beforePass));
|
||||
if (null != user) {
|
||||
user.setUserPass(SecureUtil.md5(newPass));
|
||||
userService.save(user);
|
||||
|
|
|
@ -74,7 +74,7 @@ public class ApiArchivesController {
|
|||
*/
|
||||
@GetMapping(value = "/year")
|
||||
public JsonResult archivesYear() {
|
||||
List<Archive> archives = postService.findPostGroupByYear();
|
||||
final List<Archive> archives = postService.findPostGroupByYear();
|
||||
if (null != archives && archives.size() > 0) {
|
||||
return new JsonResult(ResponseStatusEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), archives);
|
||||
} else {
|
||||
|
@ -128,7 +128,7 @@ public class ApiArchivesController {
|
|||
*/
|
||||
@GetMapping(value = "/year/month")
|
||||
public JsonResult archivesYearAndMonth() {
|
||||
List<Archive> archives = postService.findPostGroupByYearAndMonth();
|
||||
final List<Archive> archives = postService.findPostGroupByYearAndMonth();
|
||||
if (null != archives && archives.size() > 0) {
|
||||
return new JsonResult(ResponseStatusEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), archives);
|
||||
} else {
|
||||
|
|
|
@ -82,7 +82,7 @@ public class ApiCategoryController {
|
|||
*/
|
||||
@GetMapping(value = "/{cateUrl}")
|
||||
public JsonResult categories(@PathVariable("cateUrl") String cateUrl) {
|
||||
Category category = categoryService.findByCateUrl(cateUrl);
|
||||
final Category category = categoryService.findByCateUrl(cateUrl);
|
||||
if (null != category) {
|
||||
return new JsonResult(ResponseStatusEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), category);
|
||||
} else {
|
||||
|
|
|
@ -54,7 +54,7 @@ public class ApiGalleryController {
|
|||
*/
|
||||
@GetMapping
|
||||
public JsonResult galleries() {
|
||||
List<Gallery> galleries = galleryService.findAll();
|
||||
final List<Gallery> galleries = galleryService.findAll();
|
||||
if (null != galleries && galleries.size() > 0) {
|
||||
return new JsonResult(ResponseStatusEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), galleries);
|
||||
} else {
|
||||
|
@ -91,7 +91,7 @@ public class ApiGalleryController {
|
|||
*/
|
||||
@GetMapping(value = "/{id}")
|
||||
public JsonResult galleries(@PathVariable("id") Long id) {
|
||||
Optional<Gallery> gallery = galleryService.findByGalleryId(id);
|
||||
final Optional<Gallery> gallery = galleryService.findByGalleryId(id);
|
||||
if (gallery.isPresent()) {
|
||||
return new JsonResult(ResponseStatusEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), gallery.get());
|
||||
} else {
|
||||
|
|
|
@ -54,7 +54,7 @@ public class ApiLinkController {
|
|||
*/
|
||||
@GetMapping
|
||||
public JsonResult links() {
|
||||
List<Link> links = linkService.findAll();
|
||||
final List<Link> links = linkService.findAll();
|
||||
if (null != links && links.size() > 0) {
|
||||
return new JsonResult(ResponseStatusEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), links);
|
||||
} else {
|
||||
|
|
|
@ -55,7 +55,7 @@ public class ApiMenuController {
|
|||
*/
|
||||
@GetMapping
|
||||
public JsonResult menus() {
|
||||
List<Menu> menus = menuService.findAll();
|
||||
final List<Menu> menus = menuService.findAll();
|
||||
if (null != menus && menus.size() > 0) {
|
||||
return new JsonResult(ResponseStatusEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), menus);
|
||||
} else {
|
||||
|
|
|
@ -29,8 +29,8 @@ public class ApiOptionController {
|
|||
* 获取所有设置选项
|
||||
*
|
||||
* <p>
|
||||
* result json:
|
||||
* <pre>
|
||||
* result json:
|
||||
* <pre>
|
||||
* {
|
||||
* "code": 200,
|
||||
* "msg": "OK",
|
||||
|
@ -57,7 +57,7 @@ public class ApiOptionController {
|
|||
*/
|
||||
@GetMapping
|
||||
public JsonResult options() {
|
||||
Map<String, String> options = optionsService.findAllOptions();
|
||||
final Map<String, String> options = optionsService.findAllOptions();
|
||||
//去掉隐私元素
|
||||
options.remove(BlogPropertiesEnum.MAIL_SMTP_HOST.getProp());
|
||||
options.remove(BlogPropertiesEnum.MAIL_FROM_NAME.getProp());
|
||||
|
@ -71,8 +71,8 @@ public class ApiOptionController {
|
|||
* 获取单个设置项
|
||||
*
|
||||
* <p>
|
||||
* result json:
|
||||
* <pre>
|
||||
* result json:
|
||||
* <pre>
|
||||
* {
|
||||
* "code": 200,
|
||||
* "msg": "OK",
|
||||
|
@ -82,11 +82,12 @@ public class ApiOptionController {
|
|||
* </p>
|
||||
*
|
||||
* @param optionName 设置选项名称
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/{optionName}")
|
||||
public JsonResult option(@PathVariable(value = "optionName") String optionName) {
|
||||
String optionValue = optionsService.findOneOption(optionName);
|
||||
final String optionValue = optionsService.findOneOption(optionName);
|
||||
return new JsonResult(ResponseStatusEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), optionValue);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,8 +28,8 @@ public class ApiPageController {
|
|||
* 获取单个页面
|
||||
*
|
||||
* <p>
|
||||
* result json:
|
||||
* <pre>
|
||||
* result json:
|
||||
* <pre>
|
||||
* {
|
||||
* "code": 200,
|
||||
* "msg": "OK",
|
||||
|
@ -58,11 +58,12 @@ public class ApiPageController {
|
|||
* </p>
|
||||
*
|
||||
* @param postId postId
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/{postId}")
|
||||
public JsonResult pages(@PathVariable(value = "postId") Long postId) {
|
||||
Post post = postService.findByPostId(postId, PostTypeEnum.POST_TYPE_PAGE.getDesc());
|
||||
final Post post = postService.findByPostId(postId, PostTypeEnum.POST_TYPE_PAGE.getDesc());
|
||||
if (null != post) {
|
||||
postService.cacheViews(post.getPostId());
|
||||
return new JsonResult(ResponseStatusEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), post);
|
||||
|
|
|
@ -36,8 +36,8 @@ public class ApiPostController {
|
|||
* 获取文章列表 分页
|
||||
*
|
||||
* <p>
|
||||
* result api
|
||||
* <pre>
|
||||
* result api
|
||||
* <pre>
|
||||
* {
|
||||
* "code": 200,
|
||||
* "msg": "OK",
|
||||
|
@ -95,17 +95,18 @@ public class ApiPostController {
|
|||
* </p>
|
||||
*
|
||||
* @param page 页码
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/page/{page}")
|
||||
public JsonResult posts(@PathVariable(value = "page") Integer page) {
|
||||
Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
int size = 10;
|
||||
if (StrUtil.isNotBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()))) {
|
||||
size = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()));
|
||||
}
|
||||
Pageable pageable = PageRequest.of(page - 1, size, sort);
|
||||
Page<Post> posts = postService.findPostByStatus(PostStatusEnum.PUBLISHED.getCode(), PostTypeEnum.POST_TYPE_POST.getDesc(), pageable);
|
||||
final Pageable pageable = PageRequest.of(page - 1, size, sort);
|
||||
final Page<Post> posts = postService.findPostByStatus(PostStatusEnum.PUBLISHED.getCode(), PostTypeEnum.POST_TYPE_POST.getDesc(), pageable);
|
||||
if (null == posts) {
|
||||
return new JsonResult(ResponseStatusEnum.EMPTY.getCode(), ResponseStatusEnum.EMPTY.getMsg());
|
||||
}
|
||||
|
@ -116,8 +117,8 @@ public class ApiPostController {
|
|||
* 获取单个文章信息
|
||||
*
|
||||
* <p>
|
||||
* result json:
|
||||
* <pre>
|
||||
* result json:
|
||||
* <pre>
|
||||
* {
|
||||
* "code": 200,
|
||||
* "msg": "OK",
|
||||
|
@ -146,11 +147,12 @@ public class ApiPostController {
|
|||
* </p>
|
||||
*
|
||||
* @param postId 文章编号
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/{postId}")
|
||||
public JsonResult posts(@PathVariable(value = "postId") Long postId) {
|
||||
Post post = postService.findByPostId(postId, PostTypeEnum.POST_TYPE_POST.getDesc());
|
||||
final Post post = postService.findByPostId(postId, PostTypeEnum.POST_TYPE_POST.getDesc());
|
||||
if (null != post) {
|
||||
postService.cacheViews(post.getPostId());
|
||||
return new JsonResult(ResponseStatusEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), post);
|
||||
|
|
|
@ -49,7 +49,7 @@ public class ApiTagController {
|
|||
*/
|
||||
@GetMapping
|
||||
public JsonResult tags() {
|
||||
List<Tag> tags = tagService.findAll();
|
||||
final List<Tag> tags = tagService.findAll();
|
||||
if (null != tags && tags.size() > 0) {
|
||||
return new JsonResult(ResponseStatusEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), tags);
|
||||
} else {
|
||||
|
@ -80,7 +80,7 @@ public class ApiTagController {
|
|||
*/
|
||||
@GetMapping(value = "/{tagUrl}")
|
||||
public JsonResult tags(@PathVariable("tagUrl") String tagUrl) {
|
||||
Tag tag = tagService.findByTagUrl(tagUrl);
|
||||
final Tag tag = tagService.findByTagUrl(tagUrl);
|
||||
if (null != tag) {
|
||||
return new JsonResult(ResponseStatusEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), tag);
|
||||
} else {
|
||||
|
|
|
@ -50,7 +50,7 @@ public class ApiUserController {
|
|||
*/
|
||||
@GetMapping
|
||||
public JsonResult user() {
|
||||
User user = userService.findUser();
|
||||
final User user = userService.findUser();
|
||||
return new JsonResult(ResponseStatusEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), user);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,41 +1,41 @@
|
|||
package cc.ryanc.halo.web.controller.core;
|
||||
|
||||
import cn.hutool.core.text.StrBuilder;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Controller抽象类
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/12/15
|
||||
*/
|
||||
public abstract class BaseController {
|
||||
|
||||
/**
|
||||
* 定义默认主题
|
||||
*/
|
||||
public static String THEME = "anatole";
|
||||
|
||||
/**
|
||||
* 根据主题名称渲染页面
|
||||
*
|
||||
* @param pageName pageName
|
||||
* @return 返回拼接好的模板路径
|
||||
*/
|
||||
public String render(String pageName) {
|
||||
StrBuilder themeStr = new StrBuilder("themes/");
|
||||
themeStr.append(THEME);
|
||||
themeStr.append("/");
|
||||
return themeStr.append(pageName).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染404页面
|
||||
*
|
||||
* @return redirect:/404
|
||||
*/
|
||||
public String renderNotFound() {
|
||||
return "redirect:/404";
|
||||
}
|
||||
}
|
||||
package cc.ryanc.halo.web.controller.core;
|
||||
|
||||
import cn.hutool.core.text.StrBuilder;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Controller抽象类
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/12/15
|
||||
*/
|
||||
public abstract class BaseController {
|
||||
|
||||
/**
|
||||
* 定义默认主题
|
||||
*/
|
||||
public static String THEME = "anatole";
|
||||
|
||||
/**
|
||||
* 根据主题名称渲染页面
|
||||
*
|
||||
* @param pageName pageName
|
||||
* @return 返回拼接好的模板路径
|
||||
*/
|
||||
public String render(String pageName) {
|
||||
final StrBuilder themeStr = new StrBuilder("themes/");
|
||||
themeStr.append(THEME);
|
||||
themeStr.append("/");
|
||||
return themeStr.append(pageName).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染404页面
|
||||
*
|
||||
* @return redirect:/404
|
||||
*/
|
||||
public String renderNotFound() {
|
||||
return "redirect:/404";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,72 +1,72 @@
|
|||
package cc.ryanc.halo.web.controller.core;
|
||||
|
||||
import cc.ryanc.halo.model.enums.CommonParamsEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.web.servlet.error.ErrorController;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 错误页面控制器
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/12/26
|
||||
*/
|
||||
@Slf4j
|
||||
@Controller
|
||||
public class CommonController implements ErrorController {
|
||||
|
||||
private static final String ERROR_PATH = "/error";
|
||||
|
||||
/**
|
||||
* 渲染404,500
|
||||
*
|
||||
* @param request request
|
||||
* @return String
|
||||
*/
|
||||
@GetMapping(value = ERROR_PATH)
|
||||
public String handleError(HttpServletRequest request) {
|
||||
Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
|
||||
if (statusCode.equals(CommonParamsEnum.NOT_FOUND.getValue())) {
|
||||
return "redirect:/404";
|
||||
} else {
|
||||
return "redirect:/500";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染404页面
|
||||
*
|
||||
* @param model model
|
||||
* @return String
|
||||
*/
|
||||
@GetMapping(value = "/404")
|
||||
public String fourZeroFour() {
|
||||
return "common/error/404";
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染500页面
|
||||
*
|
||||
* @param model model
|
||||
* @return String
|
||||
*/
|
||||
@GetMapping(value = "/500")
|
||||
public String fiveZeroZero() {
|
||||
return "common/error/500";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path of the error page.
|
||||
*
|
||||
* @return the error path
|
||||
*/
|
||||
@Override
|
||||
public String getErrorPath() {
|
||||
return ERROR_PATH;
|
||||
}
|
||||
}
|
||||
package cc.ryanc.halo.web.controller.core;
|
||||
|
||||
import cc.ryanc.halo.model.enums.CommonParamsEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.web.servlet.error.ErrorController;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 错误页面控制器
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2017/12/26
|
||||
*/
|
||||
@Slf4j
|
||||
@Controller
|
||||
public class CommonController implements ErrorController {
|
||||
|
||||
private static final String ERROR_PATH = "/error";
|
||||
|
||||
/**
|
||||
* 渲染404,500
|
||||
*
|
||||
* @param request request
|
||||
* @return String
|
||||
*/
|
||||
@GetMapping(value = ERROR_PATH)
|
||||
public String handleError(HttpServletRequest request) {
|
||||
final Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
|
||||
if (statusCode.equals(CommonParamsEnum.NOT_FOUND.getValue())) {
|
||||
return "redirect:/404";
|
||||
} else {
|
||||
return "redirect:/500";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染404页面
|
||||
*
|
||||
* @param model model
|
||||
* @return String
|
||||
*/
|
||||
@GetMapping(value = "/404")
|
||||
public String fourZeroFour() {
|
||||
return "common/error/404";
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染500页面
|
||||
*
|
||||
* @param model model
|
||||
* @return String
|
||||
*/
|
||||
@GetMapping(value = "/500")
|
||||
public String fiveZeroZero() {
|
||||
return "common/error/500";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path of the error page.
|
||||
*
|
||||
* @return the error path
|
||||
*/
|
||||
@Override
|
||||
public String getErrorPath() {
|
||||
return ERROR_PATH;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ public class InstallController {
|
|||
return new JsonResult(ResultCodeEnum.FAIL.getCode(), "该博客已初始化,不能再次安装!");
|
||||
}
|
||||
//创建新的用户
|
||||
User user = new User();
|
||||
final User user = new User();
|
||||
user.setUserName(userName);
|
||||
if (StrUtil.isBlank(userDisplayName)) {
|
||||
userDisplayName = userName;
|
||||
|
@ -121,15 +121,15 @@ public class InstallController {
|
|||
userService.save(user);
|
||||
|
||||
//默认分类
|
||||
Category category = new Category();
|
||||
final Category category = new Category();
|
||||
category.setCateName("未分类");
|
||||
category.setCateUrl("default");
|
||||
category.setCateDesc("未分类");
|
||||
categoryService.save(category);
|
||||
|
||||
//第一篇文章
|
||||
Post post = new Post();
|
||||
List<Category> categories = new ArrayList<>();
|
||||
final Post post = new Post();
|
||||
final List<Category> categories = new ArrayList<>();
|
||||
categories.add(category);
|
||||
post.setPostTitle("Hello Halo!");
|
||||
post.setPostContentMd("# Hello Halo!\n" +
|
||||
|
@ -145,7 +145,7 @@ public class InstallController {
|
|||
postService.save(post);
|
||||
|
||||
//第一个评论
|
||||
Comment comment = new Comment();
|
||||
final Comment comment = new Comment();
|
||||
comment.setPost(post);
|
||||
comment.setCommentAuthor("ruibaby");
|
||||
comment.setCommentAuthorEmail("i@ryanc.cc");
|
||||
|
@ -159,7 +159,7 @@ public class InstallController {
|
|||
comment.setIsAdmin(0);
|
||||
commentService.save(comment);
|
||||
|
||||
Map<String, String> options = new HashMap<>();
|
||||
final Map<String, String> options = new HashMap<>();
|
||||
options.put(BlogPropertiesEnum.IS_INSTALL.getProp(), TrueFalseEnum.TRUE.getDesc());
|
||||
options.put(BlogPropertiesEnum.BLOG_LOCALE.getProp(), blogLocale);
|
||||
options.put(BlogPropertiesEnum.BLOG_TITLE.getProp(), blogTitle);
|
||||
|
@ -176,14 +176,14 @@ public class InstallController {
|
|||
//更新日志
|
||||
logsService.save(LogsRecord.INSTALL, "安装成功,欢迎使用Halo。", request);
|
||||
|
||||
Menu menuIndex = new Menu();
|
||||
final Menu menuIndex = new Menu();
|
||||
menuIndex.setMenuName("首页");
|
||||
menuIndex.setMenuUrl("/");
|
||||
menuIndex.setMenuSort(1);
|
||||
menuIndex.setMenuIcon(" ");
|
||||
menuService.save(menuIndex);
|
||||
|
||||
Menu menuArchive = new Menu();
|
||||
final Menu menuArchive = new Menu();
|
||||
menuArchive.setMenuName("归档");
|
||||
menuArchive.setMenuUrl("/archives");
|
||||
menuArchive.setMenuSort(2);
|
||||
|
|
|
@ -74,9 +74,9 @@ public class FrontArchiveController extends BaseController {
|
|||
@PathVariable(value = "page") Integer page) {
|
||||
|
||||
//所有文章数据,分页,material主题适用
|
||||
Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
Pageable pageable = PageRequest.of(page - 1, 5, sort);
|
||||
Page<Post> posts = postService.findPostByStatus(PostStatusEnum.PUBLISHED.getCode(), PostTypeEnum.POST_TYPE_POST.getDesc(), pageable);
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
final Pageable pageable = PageRequest.of(page - 1, 5, sort);
|
||||
final Page<Post> posts = postService.findPostByStatus(PostStatusEnum.PUBLISHED.getCode(), PostTypeEnum.POST_TYPE_POST.getDesc(), pageable);
|
||||
if (null == posts) {
|
||||
return this.renderNotFound();
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ public class FrontArchiveController extends BaseController {
|
|||
public String archives(Model model,
|
||||
@PathVariable(value = "year") String year,
|
||||
@PathVariable(value = "month") String month) {
|
||||
Page<Post> posts = postService.findPostByYearAndMonth(year, month, null);
|
||||
final Page<Post> posts = postService.findPostByYearAndMonth(year, month, null);
|
||||
if (null == posts) {
|
||||
return this.renderNotFound();
|
||||
}
|
||||
|
@ -119,16 +119,16 @@ public class FrontArchiveController extends BaseController {
|
|||
public String getPost(@PathVariable String postUrl,
|
||||
@RequestParam(value = "cp", defaultValue = "1") Integer cp,
|
||||
Model model) {
|
||||
Post post = postService.findByPostUrl(postUrl, PostTypeEnum.POST_TYPE_POST.getDesc());
|
||||
final Post post = postService.findByPostUrl(postUrl, PostTypeEnum.POST_TYPE_POST.getDesc());
|
||||
if (null == post || !post.getPostStatus().equals(PostStatusEnum.PUBLISHED.getCode())) {
|
||||
return this.renderNotFound();
|
||||
}
|
||||
//获得当前文章的发布日期
|
||||
Date postDate = post.getPostDate();
|
||||
final Date postDate = post.getPostDate();
|
||||
//查询当前文章日期之前的所有文章
|
||||
List<Post> beforePosts = postService.findByPostDateBefore(postDate);
|
||||
final List<Post> beforePosts = postService.findByPostDateBefore(postDate);
|
||||
//查询当前文章日期之后的所有文章
|
||||
List<Post> afterPosts = postService.findByPostDateAfter(postDate);
|
||||
final List<Post> afterPosts = postService.findByPostDateAfter(postDate);
|
||||
|
||||
if (null != beforePosts && beforePosts.size() > 0) {
|
||||
model.addAttribute("beforePost", beforePosts.get(beforePosts.size() - 1));
|
||||
|
@ -143,8 +143,8 @@ public class FrontArchiveController extends BaseController {
|
|||
comments = commentService.findCommentsByPostAndCommentStatusNot(post, CommentStatusEnum.RECYCLE.getCode());
|
||||
}
|
||||
//获取文章的标签用作keywords
|
||||
List<Tag> tags = post.getTags();
|
||||
List<String> tagWords = new ArrayList<>();
|
||||
final List<Tag> tags = post.getTags();
|
||||
final List<String> tagWords = new ArrayList<>();
|
||||
if (tags != null) {
|
||||
for (Tag tag : tags) {
|
||||
tagWords.add(tag.getTagName());
|
||||
|
@ -157,8 +157,8 @@ public class FrontArchiveController extends BaseController {
|
|||
size = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_COMMENTS.getProp()));
|
||||
}
|
||||
//评论分页
|
||||
ListPage<Comment> commentsPage = new ListPage<Comment>(CommentUtil.getComments(comments), cp, size);
|
||||
int[] rainbow = PageUtil.rainbow(cp, commentsPage.getTotalPage(), 3);
|
||||
final ListPage<Comment> commentsPage = new ListPage<Comment>(CommentUtil.getComments(comments), cp, size);
|
||||
final int[] rainbow = PageUtil.rainbow(cp, commentsPage.getTotalPage(), 3);
|
||||
model.addAttribute("is_post", true);
|
||||
model.addAttribute("post", post);
|
||||
model.addAttribute("comments", commentsPage);
|
||||
|
|
|
@ -44,11 +44,12 @@ public class FrontCategoryController extends BaseController {
|
|||
* 分类列表页面
|
||||
*
|
||||
* @param model model
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
@GetMapping
|
||||
public String categories(Model model) {
|
||||
List<Category> categories = categoryService.findAll();
|
||||
final List<Category> categories = categoryService.findAll();
|
||||
model.addAttribute("categories", categories);
|
||||
return this.render("categories");
|
||||
}
|
||||
|
@ -58,6 +59,7 @@ public class FrontCategoryController extends BaseController {
|
|||
*
|
||||
* @param model model
|
||||
* @param cateUrl cateUrl
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@GetMapping(value = "{cateUrl}")
|
||||
|
@ -72,25 +74,26 @@ public class FrontCategoryController extends BaseController {
|
|||
* @param model model
|
||||
* @param cateUrl 分类目录路径
|
||||
* @param page 页码
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
@GetMapping("{cateUrl}/page/{page}")
|
||||
public String categories(Model model,
|
||||
@PathVariable("cateUrl") String cateUrl,
|
||||
@PathVariable("page") Integer page) {
|
||||
Category category = categoryService.findByCateUrl(cateUrl);
|
||||
final Category category = categoryService.findByCateUrl(cateUrl);
|
||||
if (null == category) {
|
||||
return this.renderNotFound();
|
||||
}
|
||||
Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
Integer size = 10;
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
int size = 10;
|
||||
if (StrUtil.isNotBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()))) {
|
||||
size = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()));
|
||||
}
|
||||
Pageable pageable = PageRequest.of(page - 1, size, sort);
|
||||
Page<Post> posts = postService.findPostByCategories(category, pageable);
|
||||
int[] rainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3);
|
||||
model.addAttribute("is_categories",true);
|
||||
final Pageable pageable = PageRequest.of(page - 1, size, sort);
|
||||
final Page<Post> posts = postService.findPostByCategories(category, pageable);
|
||||
final int[] rainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3);
|
||||
model.addAttribute("is_categories", true);
|
||||
model.addAttribute("posts", posts);
|
||||
model.addAttribute("rainbow", rainbow);
|
||||
model.addAttribute("category", category);
|
||||
|
|
|
@ -65,15 +65,16 @@ public class FrontCommentController {
|
|||
* 获取文章的评论
|
||||
*
|
||||
* @param postId postId 文章编号
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
@GetMapping(value = "/getComment/{postId}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
|
||||
@ResponseBody
|
||||
public List<Comment> getComment(@PathVariable Long postId) {
|
||||
Optional<Post> post = postService.findByPostId(postId);
|
||||
Sort sort = new Sort(Sort.Direction.DESC, "commentDate");
|
||||
Pageable pageable = PageRequest.of(0, 999, sort);
|
||||
List<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post.get(), pageable, CommentStatusEnum.PUBLISHED.getCode()).getContent();
|
||||
final Optional<Post> post = postService.findByPostId(postId);
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "commentDate");
|
||||
final Pageable pageable = PageRequest.of(0, 999, sort);
|
||||
final List<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post.orElse(new Post()), pageable, CommentStatusEnum.PUBLISHED.getCode()).getContent();
|
||||
return CommentUtil.getComments(comments);
|
||||
}
|
||||
|
||||
|
@ -82,15 +83,16 @@ public class FrontCommentController {
|
|||
*
|
||||
* @param page 页码
|
||||
* @param post 当前文章
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
@GetMapping(value = "/loadComment")
|
||||
@ResponseBody
|
||||
public List<Comment> loadComment(@RequestParam(value = "page") Integer page,
|
||||
@RequestParam(value = "post") Post post) {
|
||||
Sort sort = new Sort(Sort.Direction.DESC, "commentDate");
|
||||
Pageable pageable = PageRequest.of(page - 1, 10, sort);
|
||||
List<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post, pageable, CommentStatusEnum.PUBLISHED.getCode()).getContent();
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "commentDate");
|
||||
final Pageable pageable = PageRequest.of(page - 1, 10, sort);
|
||||
final List<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post, pageable, CommentStatusEnum.PUBLISHED.getCode()).getContent();
|
||||
return comments;
|
||||
}
|
||||
|
||||
|
@ -100,6 +102,7 @@ public class FrontCommentController {
|
|||
* @param comment comment实体
|
||||
* @param post post实体
|
||||
* @param request request
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@PostMapping(value = "/newComment")
|
||||
|
@ -115,7 +118,7 @@ public class FrontCommentController {
|
|||
}
|
||||
try {
|
||||
Comment lastComment = null;
|
||||
post = postService.findByPostId(post.getPostId()).get();
|
||||
post = postService.findByPostId(post.getPostId()).orElse(new Post());
|
||||
comment.setCommentAuthorEmail(HtmlUtil.escape(comment.getCommentAuthorEmail()).toLowerCase());
|
||||
comment.setPost(post);
|
||||
comment.setCommentDate(DateUtil.date());
|
||||
|
@ -126,8 +129,8 @@ public class FrontCommentController {
|
|||
comment.setCommentAuthorAvatarMd5(SecureUtil.md5(comment.getCommentAuthorEmail()));
|
||||
}
|
||||
if (comment.getCommentParent() > 0) {
|
||||
lastComment = commentService.findCommentById(comment.getCommentParent()).get();
|
||||
StrBuilder buildContent = new StrBuilder("<a href='#comment-id-");
|
||||
lastComment = commentService.findCommentById(comment.getCommentParent()).orElse(new Comment());
|
||||
final StrBuilder buildContent = new StrBuilder("<a href='#comment-id-");
|
||||
buildContent.append(lastComment.getCommentId());
|
||||
buildContent.append("'>@");
|
||||
buildContent.append(lastComment.getCommentAuthor());
|
||||
|
@ -175,8 +178,8 @@ public class FrontCommentController {
|
|||
if (StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) {
|
||||
try {
|
||||
//发送邮件到博主
|
||||
Map<String, Object> map = new HashMap<>(5);
|
||||
StrBuilder pageUrl = new StrBuilder(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
|
||||
final Map<String, Object> map = new HashMap<>(5);
|
||||
final StrBuilder pageUrl = new StrBuilder(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
|
||||
if (StrUtil.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) {
|
||||
pageUrl.append("/archives/");
|
||||
} else {
|
||||
|
@ -217,8 +220,8 @@ public class FrontCommentController {
|
|||
//发送通知给对方
|
||||
if (StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) {
|
||||
if (Validator.isEmail(lastComment.getCommentAuthorEmail())) {
|
||||
Map<String, Object> map = new HashMap<>(8);
|
||||
StrBuilder pageUrl = new StrBuilder(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
|
||||
final Map<String, Object> map = new HashMap<>(8);
|
||||
final StrBuilder pageUrl = new StrBuilder(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()));
|
||||
if (StrUtil.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) {
|
||||
pageUrl.append("/archives/");
|
||||
|
||||
|
@ -228,7 +231,7 @@ public class FrontCommentController {
|
|||
pageUrl.append(post.getPostUrl());
|
||||
pageUrl.append("#comment-id-");
|
||||
pageUrl.append(comment.getCommentId());
|
||||
map.put("pageUrl", pageUrl.toString());
|
||||
map.put("pageUrl", pageUrl.toString());
|
||||
map.put("blogTitle", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp()));
|
||||
map.put("commentAuthor", lastComment.getCommentAuthor());
|
||||
map.put("pageName", lastComment.getPost().getPostTitle());
|
||||
|
|
|
@ -60,20 +60,19 @@ public class FrontIndexController extends BaseController {
|
|||
@GetMapping(value = "page/{page}")
|
||||
public String index(Model model,
|
||||
@PathVariable(value = "page") Integer page) {
|
||||
Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
//默认显示10条
|
||||
int size = 10;
|
||||
//尝试加载设置选项,用于设置显示条数
|
||||
if (StrUtil.isNotBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()))) {
|
||||
size = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()));
|
||||
}
|
||||
//所有文章数据,分页
|
||||
Pageable pageable = PageRequest.of(page - 1, size, sort);
|
||||
Page<Post> posts = postService.findPostByStatus(pageable);
|
||||
final Pageable pageable = PageRequest.of(page - 1, size, sort);
|
||||
final Page<Post> posts = postService.findPostByStatus(pageable);
|
||||
if (null == posts) {
|
||||
return this.renderNotFound();
|
||||
}
|
||||
int[] rainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3);
|
||||
final int[] rainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3);
|
||||
model.addAttribute("is_index",true);
|
||||
model.addAttribute("posts", posts);
|
||||
model.addAttribute("rainbow", rainbow);
|
||||
|
@ -89,7 +88,7 @@ public class FrontIndexController extends BaseController {
|
|||
*/
|
||||
@GetMapping(value = "search")
|
||||
public String search(@RequestParam("keyword") String keyword, Model model) {
|
||||
Page<Post> posts = postService.searchByKeywords(keyword, null);
|
||||
final Page<Post> posts = postService.searchByKeywords(keyword, null);
|
||||
model.addAttribute("posts", posts);
|
||||
return this.render("index");
|
||||
}
|
||||
|
|
|
@ -44,10 +44,10 @@ public class FrontOthersController {
|
|||
rssPosts = "20";
|
||||
}
|
||||
//获取文章列表并根据时间排序
|
||||
Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
Pageable pageable = PageRequest.of(0, Integer.parseInt(rssPosts), sort);
|
||||
Page<Post> postsPage = postService.findPostByStatus(0, PostTypeEnum.POST_TYPE_POST.getDesc(), pageable);
|
||||
List<Post> posts = postsPage.getContent();
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
final Pageable pageable = PageRequest.of(0, Integer.parseInt(rssPosts), sort);
|
||||
final Page<Post> postsPage = postService.findPostByStatus(0, PostTypeEnum.POST_TYPE_POST.getDesc(), pageable);
|
||||
final List<Post> posts = postsPage.getContent();
|
||||
return postService.buildRss(posts);
|
||||
}
|
||||
|
||||
|
@ -60,10 +60,10 @@ public class FrontOthersController {
|
|||
@ResponseBody
|
||||
public String siteMap() {
|
||||
//获取文章列表并根据时间排序
|
||||
Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
Pageable pageable = PageRequest.of(0, 999, sort);
|
||||
Page<Post> postsPage = postService.findPostByStatus(0, PostTypeEnum.POST_TYPE_POST.getDesc(), pageable);
|
||||
List<Post> posts = postsPage.getContent();
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
final Pageable pageable = PageRequest.of(0, 999, sort);
|
||||
final Page<Post> postsPage = postService.findPostByStatus(0, PostTypeEnum.POST_TYPE_POST.getDesc(), pageable);
|
||||
final List<Post> posts = postsPage.getContent();
|
||||
return postService.buildSiteMap(posts);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public class FrontPageController extends BaseController {
|
|||
*/
|
||||
@GetMapping(value = "/gallery")
|
||||
public String gallery(Model model) {
|
||||
List<Gallery> galleries = galleryService.findAll();
|
||||
final List<Gallery> galleries = galleryService.findAll();
|
||||
model.addAttribute("galleries", galleries);
|
||||
return this.render("gallery");
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ public class FrontPageController extends BaseController {
|
|||
public String getPage(@PathVariable(value = "postUrl") String postUrl,
|
||||
@RequestParam(value = "cp", defaultValue = "1") Integer cp,
|
||||
Model model) {
|
||||
Post post = postService.findByPostUrl(postUrl, PostTypeEnum.POST_TYPE_PAGE.getDesc());
|
||||
final Post post = postService.findByPostUrl(postUrl, PostTypeEnum.POST_TYPE_PAGE.getDesc());
|
||||
if (null == post || !post.getPostStatus().equals(PostStatusEnum.PUBLISHED.getCode())) {
|
||||
return this.renderNotFound();
|
||||
}
|
||||
|
@ -88,13 +88,12 @@ public class FrontPageController extends BaseController {
|
|||
}
|
||||
//默认显示10条
|
||||
int size = 10;
|
||||
//获取每页评论条数
|
||||
if (StrUtil.isNotBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_COMMENTS.getProp()))) {
|
||||
size = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_COMMENTS.getProp()));
|
||||
}
|
||||
//评论分页
|
||||
ListPage<Comment> commentsPage = new ListPage<Comment>(CommentUtil.getComments(comments), cp, size);
|
||||
int[] rainbow = PageUtil.rainbow(cp, commentsPage.getTotalPage(), 3);
|
||||
final ListPage<Comment> commentsPage = new ListPage<Comment>(CommentUtil.getComments(comments), cp, size);
|
||||
final int[] rainbow = PageUtil.rainbow(cp, commentsPage.getTotalPage(), 3);
|
||||
model.addAttribute("is_page", true);
|
||||
model.addAttribute("post", post);
|
||||
model.addAttribute("comments", commentsPage);
|
||||
|
|
|
@ -53,6 +53,7 @@ public class FrontTagController extends BaseController {
|
|||
*
|
||||
* @param tagUrl 标签路径
|
||||
* @param model model
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
@GetMapping(value = "{tagUrl}")
|
||||
|
@ -67,25 +68,26 @@ public class FrontTagController extends BaseController {
|
|||
* @param model model
|
||||
* @param tagUrl 标签路径
|
||||
* @param page 页码
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
@GetMapping(value = "{tagUrl}/page/{page}")
|
||||
public String tags(Model model,
|
||||
@PathVariable("tagUrl") String tagUrl,
|
||||
@PathVariable("page") Integer page) {
|
||||
Tag tag = tagService.findByTagUrl(tagUrl);
|
||||
if(null==tag){
|
||||
final Tag tag = tagService.findByTagUrl(tagUrl);
|
||||
if (null == tag) {
|
||||
return this.renderNotFound();
|
||||
}
|
||||
Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
Integer size = 10;
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
int size = 10;
|
||||
if (StrUtil.isNotBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()))) {
|
||||
size = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()));
|
||||
}
|
||||
Pageable pageable = PageRequest.of(page - 1, size, sort);
|
||||
Page<Post> posts = postService.findPostsByTags(tag, pageable);
|
||||
int[] rainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3);
|
||||
model.addAttribute("is_tags",true);
|
||||
final Pageable pageable = PageRequest.of(page - 1, size, sort);
|
||||
final Page<Post> posts = postService.findPostsByTags(tag, pageable);
|
||||
final int[] rainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3);
|
||||
model.addAttribute("is_tags", true);
|
||||
model.addAttribute("posts", posts);
|
||||
model.addAttribute("rainbow", rainbow);
|
||||
model.addAttribute("tag", tag);
|
||||
|
|
|
@ -25,10 +25,12 @@ import java.util.Map;
|
|||
@Component
|
||||
public class ApiInterceptor implements HandlerInterceptor {
|
||||
|
||||
private static final String TOKEN = "token";
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
if (StrUtil.equals(TrueFalseEnum.TRUE.getDesc(), HaloConst.OPTIONS.get(BlogPropertiesEnum.API_STATUS.getProp()))) {
|
||||
if (StrUtil.equals(request.getHeader("token"), HaloConst.OPTIONS.get(BlogPropertiesEnum.API_TOKEN.getProp()))) {
|
||||
if (StrUtil.equals(request.getHeader(TOKEN), HaloConst.OPTIONS.get(BlogPropertiesEnum.API_TOKEN.getProp()))) {
|
||||
return true;
|
||||
} else {
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
|
|
|
@ -23,6 +23,10 @@ public class LocaleInterceptor implements HandlerInterceptor {
|
|||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
final Object attribute = request.getSession().getAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME);
|
||||
if (null != attribute) {
|
||||
return true;
|
||||
}
|
||||
if (StrUtil.equals(LocaleEnum.EN_US.getValue(), HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_LOCALE.getProp()))) {
|
||||
request.getSession().setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME, new Locale("en", "US"));
|
||||
} else {
|
||||
|
|
|
@ -21,7 +21,7 @@ public class LoginInterceptor implements HandlerInterceptor {
|
|||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
Object obj = request.getSession().getAttribute(HaloConst.USER_SESSION_KEY);
|
||||
final Object obj = request.getSession().getAttribute(HaloConst.USER_SESSION_KEY);
|
||||
//如果user不为空则放行
|
||||
if (null != obj) {
|
||||
return true;
|
||||
|
|
|
@ -159,7 +159,7 @@
|
|||
autofocus: true,
|
||||
autosave: {
|
||||
enabled: true,
|
||||
uniqueId: "editor-temp-page-<#if post??>${post.postId}<#else>1</#if>",
|
||||
uniqueId: "editor-temp-page-<#if post??>${post.postId?c}<#else>1</#if>",
|
||||
delay: 10000
|
||||
},
|
||||
renderingConfig: {
|
||||
|
|
|
@ -177,7 +177,7 @@
|
|||
autofocus: true,
|
||||
autosave: {
|
||||
enabled: true,
|
||||
uniqueId: "editor-temp-${post.postId!}",
|
||||
uniqueId: "editor-temp-${post.postId?c}",
|
||||
delay: 10000
|
||||
},
|
||||
renderingConfig: {
|
||||
|
|
Loading…
Reference in New Issue