mirror of https://github.com/halo-dev/halo
🎨 代码优化
parent
ccb8509503
commit
e164d4c30a
|
@ -0,0 +1,42 @@
|
|||
package cc.ryanc.halo.model.enums;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 常用数字
|
||||
* </pre>
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/8/1
|
||||
*/
|
||||
public enum CommonParams {
|
||||
|
||||
/**
|
||||
* 数字10
|
||||
*/
|
||||
TEN(10),
|
||||
|
||||
/**
|
||||
* 数字5
|
||||
*/
|
||||
FIVE(5),
|
||||
|
||||
/**
|
||||
* 数字404
|
||||
*/
|
||||
NOT_FOUND(404),
|
||||
|
||||
/**
|
||||
* 数字1024
|
||||
*/
|
||||
BYTE(1024);
|
||||
|
||||
private Integer value;
|
||||
|
||||
CommonParams(Integer value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
|
@ -54,5 +54,11 @@ public interface CategoryService {
|
|||
*/
|
||||
Category findByCateUrl(String cateUrl);
|
||||
|
||||
/**
|
||||
* 将分类字符串集合转化为Category泛型集合
|
||||
*
|
||||
* @param strings strings
|
||||
* @return List
|
||||
*/
|
||||
List<Category> strListToCateList(List<String> strings);
|
||||
}
|
||||
|
|
|
@ -80,6 +80,12 @@ public class CategoryServiceImpl implements CategoryService {
|
|||
return categoryRepository.findCategoryByCateUrl(cateUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将分类字符串集合转化为Category泛型集合
|
||||
*
|
||||
* @param strings strings
|
||||
* @return List
|
||||
*/
|
||||
@Override
|
||||
public List<Category> strListToCateList(List<String> strings) {
|
||||
if (null == strings) {
|
||||
|
|
|
@ -5,6 +5,7 @@ import cc.ryanc.halo.model.dto.BackupDto;
|
|||
import cc.ryanc.halo.model.dto.HaloConst;
|
||||
import cc.ryanc.halo.model.dto.Theme;
|
||||
import cc.ryanc.halo.model.enums.BlogProperties;
|
||||
import cc.ryanc.halo.model.enums.CommonParams;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import com.sun.syndication.feed.rss.Channel;
|
||||
import com.sun.syndication.feed.rss.Content;
|
||||
|
@ -114,17 +115,17 @@ public class HaloUtils {
|
|||
* @return String
|
||||
*/
|
||||
public static String parseSize(long size) {
|
||||
if (size < 1024) {
|
||||
if (size < CommonParams.NOT_FOUND.getValue()) {
|
||||
return String.valueOf(size) + "B";
|
||||
} else {
|
||||
size = size / 1024;
|
||||
}
|
||||
if (size < 1024) {
|
||||
if (size < CommonParams.NOT_FOUND.getValue()) {
|
||||
return String.valueOf(size) + "KB";
|
||||
} else {
|
||||
size = size / 1024;
|
||||
}
|
||||
if (size < 1024) {
|
||||
if (size < CommonParams.NOT_FOUND.getValue()) {
|
||||
size = size * 100;
|
||||
return String.valueOf((size / 100)) + "." + String.valueOf((size % 100)) + "MB";
|
||||
} else {
|
||||
|
|
|
@ -7,6 +7,7 @@ import cc.ryanc.halo.model.domain.User;
|
|||
import cc.ryanc.halo.model.dto.HaloConst;
|
||||
import cc.ryanc.halo.model.dto.JsonResult;
|
||||
import cc.ryanc.halo.model.dto.LogsRecord;
|
||||
import cc.ryanc.halo.model.enums.CommonParams;
|
||||
import cc.ryanc.halo.model.enums.ResultCode;
|
||||
import cc.ryanc.halo.model.enums.TrueFalse;
|
||||
import cc.ryanc.halo.service.*;
|
||||
|
@ -137,7 +138,7 @@ public class AdminController extends BaseController {
|
|||
loginLast = aUser.getLoginLast();
|
||||
}
|
||||
Long between = DateUtil.between(loginLast, DateUtil.date(), DateUnit.MINUTE);
|
||||
if (StringUtils.equals(aUser.getLoginEnable(), TrueFalse.FALSE.getDesc()) && (between < 10)) {
|
||||
if (StringUtils.equals(aUser.getLoginEnable(), TrueFalse.FALSE.getDesc()) && (between < CommonParams.TEN.getValue())) {
|
||||
return new JsonResult(ResultCode.FAIL.getCode(), "已禁止登录,请10分钟后再试");
|
||||
}
|
||||
//验证用户名和密码
|
||||
|
@ -160,7 +161,7 @@ public class AdminController extends BaseController {
|
|||
//更新失败次数
|
||||
Integer errorCount = userService.updateUserLoginError();
|
||||
//超过五次禁用账户
|
||||
if (errorCount >= 5) {
|
||||
if (errorCount >= CommonParams.FIVE.getValue()) {
|
||||
userService.updateUserLoginEnable(TrueFalse.FALSE.getDesc());
|
||||
}
|
||||
logsService.saveByLogs(
|
||||
|
|
|
@ -59,7 +59,7 @@ public class BackupController {
|
|||
@GetMapping
|
||||
public String backup(@RequestParam(value = "type", defaultValue = "resources") String type, Model model) {
|
||||
List<BackupDto> backups = null;
|
||||
if (StringUtils.equals(type,BackupType.RESOURCES.getDesc())) {
|
||||
if (StringUtils.equals(type, BackupType.RESOURCES.getDesc())) {
|
||||
backups = HaloUtils.getBackUps(BackupType.RESOURCES.getDesc());
|
||||
} else if (StringUtils.equals(type, BackupType.DATABASES.getDesc())) {
|
||||
backups = HaloUtils.getBackUps(BackupType.DATABASES.getDesc());
|
||||
|
@ -100,7 +100,7 @@ public class BackupController {
|
|||
*/
|
||||
public JsonResult backupDatabase() {
|
||||
try {
|
||||
if (HaloUtils.getBackUps(BackupType.DATABASES.getDesc()).size() > 10) {
|
||||
if (HaloUtils.getBackUps(BackupType.DATABASES.getDesc()).size() > CommonParams.TEN.getValue()) {
|
||||
FileUtil.del(System.getProperties().getProperty("user.home") + "/halo/backup/databases/");
|
||||
}
|
||||
String srcPath = System.getProperties().getProperty("user.home") + "/halo/";
|
||||
|
@ -122,7 +122,7 @@ public class BackupController {
|
|||
*/
|
||||
public JsonResult backupResources() {
|
||||
try {
|
||||
if (HaloUtils.getBackUps(BackupType.RESOURCES.getDesc()).size() > 10) {
|
||||
if (HaloUtils.getBackUps(BackupType.RESOURCES.getDesc()).size() > CommonParams.TEN.getValue()) {
|
||||
FileUtil.del(System.getProperties().getProperty("user.home") + "/halo/backup/resources/");
|
||||
}
|
||||
File path = new File(ResourceUtils.getURL("classpath:").getPath());
|
||||
|
@ -147,7 +147,7 @@ public class BackupController {
|
|||
List<Post> posts = postService.findAllPosts(PostType.POST_TYPE_POST.getDesc());
|
||||
posts.addAll(postService.findAllPosts(PostType.POST_TYPE_PAGE.getDesc()));
|
||||
try {
|
||||
if (HaloUtils.getBackUps(BackupType.POSTS.getDesc()).size() > 10) {
|
||||
if (HaloUtils.getBackUps(BackupType.POSTS.getDesc()).size() > CommonParams.TEN.getValue()) {
|
||||
FileUtil.del(System.getProperties().getProperty("user.home") + "/halo/backup/posts/");
|
||||
}
|
||||
//打包好的文件名
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cc.ryanc.halo.web.controller.core;
|
||||
|
||||
import cc.ryanc.halo.model.enums.CommonParams;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.web.servlet.error.ErrorController;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
@ -30,7 +31,7 @@ public class CommonController implements ErrorController {
|
|||
@GetMapping(value = ERROR_PATH)
|
||||
public String handleError(HttpServletRequest request) {
|
||||
Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
|
||||
if (statusCode == 404) {
|
||||
if (statusCode.equals(CommonParams.NOT_FOUND.getValue())) {
|
||||
return "redirect:/404";
|
||||
} else {
|
||||
return "redirect:/500";
|
||||
|
|
Loading…
Reference in New Issue