mirror of https://github.com/halo-dev/halo
🎨 代码优化
parent
2998da98e4
commit
0242fcea37
|
@ -4,6 +4,7 @@ import cc.ryanc.halo.model.domain.Logs;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@ -20,17 +21,11 @@ public interface LogsService {
|
||||||
/**
|
/**
|
||||||
* 保存日志
|
* 保存日志
|
||||||
*
|
*
|
||||||
* @param logs logs
|
* @param logTitle logTitle
|
||||||
* @return Logs
|
* @param logContent logContent
|
||||||
|
* @param request request
|
||||||
*/
|
*/
|
||||||
Logs saveByLogs(Logs logs);
|
void save(String logTitle, String logContent, HttpServletRequest request);
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据编号移除
|
|
||||||
*
|
|
||||||
* @param logsId logsId
|
|
||||||
*/
|
|
||||||
void removeByLogsId(Long logsId);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 移除所有日志
|
* 移除所有日志
|
||||||
|
|
|
@ -223,7 +223,6 @@ public class AttachmentServiceImpl implements AttachmentService {
|
||||||
fileSmallPath.append("_small.");
|
fileSmallPath.append("_small.");
|
||||||
fileSmallPath.append(fileSuffix);
|
fileSmallPath.append(fileSuffix);
|
||||||
|
|
||||||
|
|
||||||
String size = HaloUtils.parseSize(new File(fullPath.toString()).length());
|
String size = HaloUtils.parseSize(new File(fullPath.toString()).length());
|
||||||
String wh = HaloUtils.getImageWh(new File(fullPath.toString()));
|
String wh = HaloUtils.getImageWh(new File(fullPath.toString()));
|
||||||
|
|
||||||
|
@ -258,7 +257,7 @@ public class AttachmentServiceImpl implements AttachmentService {
|
||||||
String domain = HaloConst.OPTIONS.get("qiniu_domain");
|
String domain = HaloConst.OPTIONS.get("qiniu_domain");
|
||||||
String bucket = HaloConst.OPTIONS.get("qiniu_bucket");
|
String bucket = HaloConst.OPTIONS.get("qiniu_bucket");
|
||||||
String smallUrl = HaloConst.OPTIONS.get("qiniu_small_url");
|
String smallUrl = HaloConst.OPTIONS.get("qiniu_small_url");
|
||||||
if (accessKey == null || secretKey == null || domain == null || bucket == null) {
|
if (StrUtil.isEmpty(accessKey) || StrUtil.isEmpty(secretKey) || StrUtil.isEmpty(domain) || StrUtil.isEmpty(bucket)) {
|
||||||
return resultMap;
|
return resultMap;
|
||||||
}
|
}
|
||||||
Auth auth = Auth.create(accessKey, secretKey);
|
Auth auth = Auth.create(accessKey, secretKey);
|
||||||
|
@ -318,7 +317,7 @@ public class AttachmentServiceImpl implements AttachmentService {
|
||||||
String domain = HaloConst.OPTIONS.get("upyun_oss_domain");
|
String domain = HaloConst.OPTIONS.get("upyun_oss_domain");
|
||||||
String operator = HaloConst.OPTIONS.get("upyun_oss_operator");
|
String operator = HaloConst.OPTIONS.get("upyun_oss_operator");
|
||||||
String smallUrl = HaloConst.OPTIONS.get("upyun_oss_small");
|
String smallUrl = HaloConst.OPTIONS.get("upyun_oss_small");
|
||||||
if (ossSrc == null || ossPwd == null || domain == null || bucket == null || operator == null) {
|
if (StrUtil.isEmpty(ossSrc) || StrUtil.isEmpty(ossPwd) || StrUtil.isEmpty(domain) || StrUtil.isEmpty(bucket) || StrUtil.isEmpty(operator)) {
|
||||||
return resultMap;
|
return resultMap;
|
||||||
}
|
}
|
||||||
String fileName = file.getOriginalFilename();
|
String fileName = file.getOriginalFilename();
|
||||||
|
@ -363,7 +362,7 @@ public class AttachmentServiceImpl implements AttachmentService {
|
||||||
String accessKey = HaloConst.OPTIONS.get("qiniu_access_key");
|
String accessKey = HaloConst.OPTIONS.get("qiniu_access_key");
|
||||||
String secretKey = HaloConst.OPTIONS.get("qiniu_secret_key");
|
String secretKey = HaloConst.OPTIONS.get("qiniu_secret_key");
|
||||||
String bucket = HaloConst.OPTIONS.get("qiniu_bucket");
|
String bucket = HaloConst.OPTIONS.get("qiniu_bucket");
|
||||||
if (accessKey == null || secretKey == null || bucket == null) {
|
if (StrUtil.isEmpty(accessKey) || StrUtil.isEmpty(secretKey) || StrUtil.isEmpty(bucket)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Auth auth = Auth.create(accessKey, secretKey);
|
Auth auth = Auth.create(accessKey, secretKey);
|
||||||
|
@ -391,7 +390,7 @@ public class AttachmentServiceImpl implements AttachmentService {
|
||||||
String ossPwd = HaloConst.OPTIONS.get("upyun_oss_pwd");
|
String ossPwd = HaloConst.OPTIONS.get("upyun_oss_pwd");
|
||||||
String bucket = HaloConst.OPTIONS.get("upyun_oss_bucket");
|
String bucket = HaloConst.OPTIONS.get("upyun_oss_bucket");
|
||||||
String operator = HaloConst.OPTIONS.get("upyun_oss_operator");
|
String operator = HaloConst.OPTIONS.get("upyun_oss_operator");
|
||||||
if (ossSrc == null || ossPwd == null || bucket == null || operator == null) {
|
if (StrUtil.isEmpty(ossSrc) || StrUtil.isEmpty(ossPwd) || StrUtil.isEmpty(bucket) || StrUtil.isEmpty(operator)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
UpYun upYun = new UpYun(bucket, operator, ossPwd);
|
UpYun upYun = new UpYun(bucket, operator, ossPwd);
|
||||||
|
|
|
@ -3,11 +3,14 @@ package cc.ryanc.halo.service.impl;
|
||||||
import cc.ryanc.halo.model.domain.Logs;
|
import cc.ryanc.halo.model.domain.Logs;
|
||||||
import cc.ryanc.halo.repository.LogsRepository;
|
import cc.ryanc.halo.repository.LogsRepository;
|
||||||
import cc.ryanc.halo.service.LogsService;
|
import cc.ryanc.halo.service.LogsService;
|
||||||
|
import cn.hutool.extra.servlet.ServletUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@ -28,23 +31,18 @@ public class LogsServiceImpl implements LogsService {
|
||||||
/**
|
/**
|
||||||
* 保存日志
|
* 保存日志
|
||||||
*
|
*
|
||||||
* @param logs logs
|
* @param logTitle logTitle
|
||||||
* @return Logs
|
* @param logContent logContent
|
||||||
|
* @param request request
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Logs saveByLogs(Logs logs) {
|
public void save(String logTitle, String logContent, HttpServletRequest request) {
|
||||||
return logsRepository.save(logs);
|
Logs logs = new Logs();
|
||||||
}
|
logs.setLogTitle(logTitle);
|
||||||
|
logs.setLogContent(logContent);
|
||||||
/**
|
logs.setLogCreated(new Date());
|
||||||
* 根据编号移除
|
logs.setLogIp(ServletUtil.getClientIP(request));
|
||||||
*
|
logsRepository.save(logs);
|
||||||
* @param logsId logsId
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void removeByLogsId(Long logsId) {
|
|
||||||
Optional<Logs> logs = this.findLogsByLogsId(logsId);
|
|
||||||
logsRepository.delete(logs.get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -20,7 +20,6 @@ import cn.hutool.core.lang.Validator;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.crypto.SecureUtil;
|
import cn.hutool.crypto.SecureUtil;
|
||||||
import cn.hutool.extra.servlet.ServletUtil;
|
|
||||||
import cn.hutool.http.HtmlUtil;
|
import cn.hutool.http.HtmlUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -160,7 +159,7 @@ public class AdminController extends BaseController {
|
||||||
session.setAttribute(HaloConst.USER_SESSION_KEY, aUser);
|
session.setAttribute(HaloConst.USER_SESSION_KEY, aUser);
|
||||||
//重置用户的登录状态为正常
|
//重置用户的登录状态为正常
|
||||||
userService.updateUserNormal();
|
userService.updateUserNormal();
|
||||||
logsService.saveByLogs(new Logs(LogsRecord.LOGIN, LogsRecord.LOGIN_SUCCESS, ServletUtil.getClientIP(request), DateUtil.date()));
|
logsService.save(LogsRecord.LOGIN, LogsRecord.LOGIN_SUCCESS, request);
|
||||||
log.info("User {} login succeeded.", aUser.getUserDisplayName());
|
log.info("User {} login succeeded.", aUser.getUserDisplayName());
|
||||||
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.login.success"));
|
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.login.success"));
|
||||||
} else {
|
} else {
|
||||||
|
@ -170,14 +169,7 @@ public class AdminController extends BaseController {
|
||||||
if (errorCount >= CommonParamsEnum.FIVE.getValue()) {
|
if (errorCount >= CommonParamsEnum.FIVE.getValue()) {
|
||||||
userService.updateUserLoginEnable(TrueFalseEnum.FALSE.getDesc());
|
userService.updateUserLoginEnable(TrueFalseEnum.FALSE.getDesc());
|
||||||
}
|
}
|
||||||
logsService.saveByLogs(
|
logsService.save(LogsRecord.LOGIN, LogsRecord.LOGIN_ERROR + "[" + HtmlUtil.escape(loginName) + "," + HtmlUtil.escape(loginPwd) + "]", request);
|
||||||
new Logs(
|
|
||||||
LogsRecord.LOGIN,
|
|
||||||
LogsRecord.LOGIN_ERROR + "[" + HtmlUtil.escape(loginName) + "," + HtmlUtil.escape(loginPwd) + "]",
|
|
||||||
ServletUtil.getClientIP(request),
|
|
||||||
DateUtil.date()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
Object[] args = {(5 - errorCount)};
|
Object[] args = {(5 - errorCount)};
|
||||||
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.login.failed", args));
|
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.login.failed", args));
|
||||||
}
|
}
|
||||||
|
@ -193,7 +185,7 @@ public class AdminController extends BaseController {
|
||||||
public String logOut(HttpSession session) {
|
public String logOut(HttpSession session) {
|
||||||
User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
|
User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
|
||||||
session.removeAttribute(HaloConst.USER_SESSION_KEY);
|
session.removeAttribute(HaloConst.USER_SESSION_KEY);
|
||||||
logsService.saveByLogs(new Logs(LogsRecord.LOGOUT, user.getUserName(), ServletUtil.getClientIP(request), DateUtil.date()));
|
logsService.save(LogsRecord.LOGOUT, user.getUserName(), request);
|
||||||
log.info("User {} has logged out", user.getUserName());
|
log.info("User {} has logged out", user.getUserName());
|
||||||
return "redirect:/admin/login";
|
return "redirect:/admin/login";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package cc.ryanc.halo.web.controller.admin;
|
package cc.ryanc.halo.web.controller.admin;
|
||||||
|
|
||||||
import cc.ryanc.halo.model.domain.Attachment;
|
import cc.ryanc.halo.model.domain.Attachment;
|
||||||
import cc.ryanc.halo.model.domain.Logs;
|
|
||||||
import cc.ryanc.halo.model.dto.JsonResult;
|
import cc.ryanc.halo.model.dto.JsonResult;
|
||||||
import cc.ryanc.halo.model.dto.LogsRecord;
|
import cc.ryanc.halo.model.dto.LogsRecord;
|
||||||
import cc.ryanc.halo.model.enums.PostTypeEnum;
|
import cc.ryanc.halo.model.enums.PostTypeEnum;
|
||||||
|
@ -11,7 +10,6 @@ import cc.ryanc.halo.service.LogsService;
|
||||||
import cc.ryanc.halo.utils.LocaleMessageUtil;
|
import cc.ryanc.halo.utils.LocaleMessageUtil;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.extra.servlet.ServletUtil;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
|
@ -116,13 +114,12 @@ public class AttachmentController {
|
||||||
public Map<String, Object> upload(@RequestParam("file") MultipartFile file,
|
public Map<String, Object> upload(@RequestParam("file") MultipartFile file,
|
||||||
HttpServletRequest request) {
|
HttpServletRequest request) {
|
||||||
Map<String, Object> result = new HashMap<>(3);
|
Map<String, Object> result = new HashMap<>(3);
|
||||||
System.out.println("源地址" + file.getOriginalFilename() + "类型" + file.getContentType() + "文件名" + file.getName() + "文件大小" + file.getSize());
|
|
||||||
if (!file.isEmpty()) {
|
if (!file.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
Map<String, String> resultMap = attachmentService.upload(file, request);
|
Map<String, String> resultMap = attachmentService.upload(file, request);
|
||||||
if (resultMap == null || resultMap.isEmpty()) {
|
if (resultMap == null || resultMap.isEmpty()) {
|
||||||
log.error("文件上传失败");
|
log.error("File upload failed");
|
||||||
result.put("success", 0);
|
result.put("success", ResultCodeEnum.FAIL.getCode());
|
||||||
result.put("message", localeMessageUtil.getMessage("code.admin.attachment.upload-failed"));
|
result.put("message", localeMessageUtil.getMessage("code.admin.attachment.upload-failed"));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -139,16 +136,14 @@ public class AttachmentController {
|
||||||
attachment.setAttachLocation(resultMap.get("location"));
|
attachment.setAttachLocation(resultMap.get("location"));
|
||||||
attachmentService.saveByAttachment(attachment);
|
attachmentService.saveByAttachment(attachment);
|
||||||
log.info("Upload file {} to {} successfully", resultMap.get("fileName"), resultMap.get("filePath"));
|
log.info("Upload file {} to {} successfully", resultMap.get("fileName"), resultMap.get("filePath"));
|
||||||
logsService.saveByLogs(
|
result.put("success", ResultCodeEnum.SUCCESS.getCode());
|
||||||
new Logs(LogsRecord.UPLOAD_FILE, resultMap.get("fileName"), ServletUtil.getClientIP(request), DateUtil.date())
|
|
||||||
);
|
|
||||||
result.put("success", 1);
|
|
||||||
result.put("message", localeMessageUtil.getMessage("code.admin.attachment.upload-success"));
|
result.put("message", localeMessageUtil.getMessage("code.admin.attachment.upload-success"));
|
||||||
result.put("url", attachment.getAttachPath());
|
result.put("url", attachment.getAttachPath());
|
||||||
result.put("filename", resultMap.get("filePath"));
|
result.put("filename", resultMap.get("filePath"));
|
||||||
|
logsService.save(LogsRecord.UPLOAD_FILE, resultMap.get("fileName"), request);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Upload file failed:{}", e.getMessage());
|
log.error("Upload file failed:{}", e.getMessage());
|
||||||
result.put("success", 0);
|
result.put("success", ResultCodeEnum.FAIL.getCode());
|
||||||
result.put("message", localeMessageUtil.getMessage("code.admin.attachment.upload-failed"));
|
result.put("message", localeMessageUtil.getMessage("code.admin.attachment.upload-failed"));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -216,9 +211,7 @@ public class AttachmentController {
|
||||||
}
|
}
|
||||||
if (flag) {
|
if (flag) {
|
||||||
log.info("Delete file {} successfully!", delFileName);
|
log.info("Delete file {} successfully!", delFileName);
|
||||||
logsService.saveByLogs(
|
logsService.save(LogsRecord.REMOVE_FILE, delFileName, request);
|
||||||
new Logs(LogsRecord.REMOVE_FILE, delFileName, ServletUtil.getClientIP(request), DateUtil.date())
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
log.error("Deleting attachment {} failed!", delFileName);
|
log.error("Deleting attachment {} failed!", delFileName);
|
||||||
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.common.delete-failed"));
|
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.common.delete-failed"));
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package cc.ryanc.halo.web.controller.admin;
|
package cc.ryanc.halo.web.controller.admin;
|
||||||
|
|
||||||
import cc.ryanc.halo.model.domain.*;
|
import cc.ryanc.halo.model.domain.Gallery;
|
||||||
|
import cc.ryanc.halo.model.domain.Link;
|
||||||
|
import cc.ryanc.halo.model.domain.Post;
|
||||||
|
import cc.ryanc.halo.model.domain.User;
|
||||||
import cc.ryanc.halo.model.dto.HaloConst;
|
import cc.ryanc.halo.model.dto.HaloConst;
|
||||||
import cc.ryanc.halo.model.dto.JsonResult;
|
import cc.ryanc.halo.model.dto.JsonResult;
|
||||||
import cc.ryanc.halo.model.dto.LogsRecord;
|
import cc.ryanc.halo.model.dto.LogsRecord;
|
||||||
|
@ -17,7 +20,6 @@ import cc.ryanc.halo.utils.MarkdownUtils;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.RandomUtil;
|
import cn.hutool.core.util.RandomUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.extra.servlet.ServletUtil;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.propertyeditors.CustomDateEditor;
|
import org.springframework.beans.propertyeditors.CustomDateEditor;
|
||||||
|
@ -211,7 +213,7 @@ public class PageController {
|
||||||
@GetMapping(value = "/new")
|
@GetMapping(value = "/new")
|
||||||
public String newPage(Model model) {
|
public String newPage(Model model) {
|
||||||
List<String> customTpls = HaloUtils.getCustomTpl(HaloConst.OPTIONS.get(BlogPropertiesEnum.THEME.getProp()));
|
List<String> customTpls = HaloUtils.getCustomTpl(HaloConst.OPTIONS.get(BlogPropertiesEnum.THEME.getProp()));
|
||||||
model.addAttribute("customTpls",customTpls);
|
model.addAttribute("customTpls", customTpls);
|
||||||
return "admin/admin_page_md_editor";
|
return "admin/admin_page_md_editor";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,7 +249,7 @@ public class PageController {
|
||||||
post.setPostThumbnail("/static/images/thumbnail/thumbnail-" + RandomUtil.randomInt(1, 10) + ".jpg");
|
post.setPostThumbnail("/static/images/thumbnail/thumbnail-" + RandomUtil.randomInt(1, 10) + ".jpg");
|
||||||
}
|
}
|
||||||
postService.saveByPost(post);
|
postService.saveByPost(post);
|
||||||
logsService.saveByLogs(new Logs(LogsRecord.PUSH_PAGE, post.getPostTitle(), ServletUtil.getClientIP(request), DateUtil.date()));
|
logsService.save(LogsRecord.PUSH_PAGE, post.getPostTitle(), request);
|
||||||
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), msg);
|
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), msg);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Save page failed: {}", e.getMessage());
|
log.error("Save page failed: {}", e.getMessage());
|
||||||
|
@ -267,7 +269,7 @@ public class PageController {
|
||||||
Optional<Post> post = postService.findByPostId(pageId);
|
Optional<Post> post = postService.findByPostId(pageId);
|
||||||
List<String> customTpls = HaloUtils.getCustomTpl(HaloConst.OPTIONS.get(BlogPropertiesEnum.THEME.getProp()));
|
List<String> customTpls = HaloUtils.getCustomTpl(HaloConst.OPTIONS.get(BlogPropertiesEnum.THEME.getProp()));
|
||||||
model.addAttribute("post", post.orElse(new Post()));
|
model.addAttribute("post", post.orElse(new Post()));
|
||||||
model.addAttribute("customTpls",customTpls);
|
model.addAttribute("customTpls", customTpls);
|
||||||
return "admin/admin_page_md_editor";
|
return "admin/admin_page_md_editor";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package cc.ryanc.halo.web.controller.admin;
|
package cc.ryanc.halo.web.controller.admin;
|
||||||
|
|
||||||
import cc.ryanc.halo.model.domain.*;
|
import cc.ryanc.halo.model.domain.Category;
|
||||||
|
import cc.ryanc.halo.model.domain.Post;
|
||||||
|
import cc.ryanc.halo.model.domain.Tag;
|
||||||
|
import cc.ryanc.halo.model.domain.User;
|
||||||
import cc.ryanc.halo.model.dto.HaloConst;
|
import cc.ryanc.halo.model.dto.HaloConst;
|
||||||
import cc.ryanc.halo.model.dto.JsonResult;
|
import cc.ryanc.halo.model.dto.JsonResult;
|
||||||
import cc.ryanc.halo.model.dto.LogsRecord;
|
import cc.ryanc.halo.model.dto.LogsRecord;
|
||||||
|
@ -19,7 +22,6 @@ import cc.ryanc.halo.web.controller.core.BaseController;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.RandomUtil;
|
import cn.hutool.core.util.RandomUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.extra.servlet.ServletUtil;
|
|
||||||
import cn.hutool.http.HtmlUtil;
|
import cn.hutool.http.HtmlUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -213,7 +215,7 @@ public class PostController extends BaseController {
|
||||||
post.setPostThumbnail("/static/images/thumbnail/thumbnail-" + RandomUtil.randomInt(1, 10) + ".jpg");
|
post.setPostThumbnail("/static/images/thumbnail/thumbnail-" + RandomUtil.randomInt(1, 10) + ".jpg");
|
||||||
}
|
}
|
||||||
postService.saveByPost(post);
|
postService.saveByPost(post);
|
||||||
logsService.saveByLogs(new Logs(LogsRecord.PUSH_POST, post.getPostTitle(), ServletUtil.getClientIP(request), DateUtil.date()));
|
logsService.save(LogsRecord.PUSH_POST, post.getPostTitle(), request);
|
||||||
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), msg);
|
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), msg);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Save article failed: {}", e.getMessage());
|
log.error("Save article failed: {}", e.getMessage());
|
||||||
|
@ -268,7 +270,7 @@ public class PostController extends BaseController {
|
||||||
try {
|
try {
|
||||||
Optional<Post> post = postService.findByPostId(postId);
|
Optional<Post> post = postService.findByPostId(postId);
|
||||||
postService.removeByPostId(postId);
|
postService.removeByPostId(postId);
|
||||||
logsService.saveByLogs(new Logs(LogsRecord.REMOVE_POST, post.get().getPostTitle(), ServletUtil.getClientIP(request), DateUtil.date()));
|
logsService.save(LogsRecord.REMOVE_POST, post.get().getPostTitle(), request);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Delete article failed: {}", e.getMessage());
|
log.error("Delete article failed: {}", e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package cc.ryanc.halo.web.controller.admin;
|
package cc.ryanc.halo.web.controller.admin;
|
||||||
|
|
||||||
import cc.ryanc.halo.model.domain.Logs;
|
|
||||||
import cc.ryanc.halo.model.dto.HaloConst;
|
import cc.ryanc.halo.model.dto.HaloConst;
|
||||||
import cc.ryanc.halo.model.dto.JsonResult;
|
import cc.ryanc.halo.model.dto.JsonResult;
|
||||||
import cc.ryanc.halo.model.dto.LogsRecord;
|
import cc.ryanc.halo.model.dto.LogsRecord;
|
||||||
|
@ -12,14 +11,12 @@ import cc.ryanc.halo.service.OptionsService;
|
||||||
import cc.ryanc.halo.utils.HaloUtils;
|
import cc.ryanc.halo.utils.HaloUtils;
|
||||||
import cc.ryanc.halo.utils.LocaleMessageUtil;
|
import cc.ryanc.halo.utils.LocaleMessageUtil;
|
||||||
import cc.ryanc.halo.web.controller.core.BaseController;
|
import cc.ryanc.halo.web.controller.core.BaseController;
|
||||||
import cn.hutool.core.date.DateUtil;
|
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.io.file.FileReader;
|
import cn.hutool.core.io.file.FileReader;
|
||||||
import cn.hutool.core.io.file.FileWriter;
|
import cn.hutool.core.io.file.FileWriter;
|
||||||
import cn.hutool.core.util.RuntimeUtil;
|
import cn.hutool.core.util.RuntimeUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.core.util.ZipUtil;
|
import cn.hutool.core.util.ZipUtil;
|
||||||
import cn.hutool.extra.servlet.ServletUtil;
|
|
||||||
import freemarker.template.Configuration;
|
import freemarker.template.Configuration;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -99,9 +96,7 @@ public class ThemeController extends BaseController {
|
||||||
configuration.setSharedVariable("themeName", siteTheme);
|
configuration.setSharedVariable("themeName", siteTheme);
|
||||||
configuration.setSharedVariable("options", HaloConst.OPTIONS);
|
configuration.setSharedVariable("options", HaloConst.OPTIONS);
|
||||||
log.info("Changed theme to {}", siteTheme);
|
log.info("Changed theme to {}", siteTheme);
|
||||||
logsService.saveByLogs(
|
logsService.save(LogsRecord.CHANGE_THEME, "更换为" + siteTheme, request);
|
||||||
new Logs(LogsRecord.CHANGE_THEME, "更换为" + siteTheme, ServletUtil.getClientIP(request), DateUtil.date())
|
|
||||||
);
|
|
||||||
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.theme.change-success", new Object[]{siteTheme}));
|
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.theme.change-success", new Object[]{siteTheme}));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.theme.change-failed"));
|
return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.theme.change-failed"));
|
||||||
|
@ -126,9 +121,7 @@ public class ThemeController extends BaseController {
|
||||||
File themePath = new File(basePath.getAbsolutePath(), new StringBuffer("templates/themes/").append(file.getOriginalFilename()).toString());
|
File themePath = new File(basePath.getAbsolutePath(), new StringBuffer("templates/themes/").append(file.getOriginalFilename()).toString());
|
||||||
file.transferTo(themePath);
|
file.transferTo(themePath);
|
||||||
log.info("Upload topic success, path is " + themePath.getAbsolutePath());
|
log.info("Upload topic success, path is " + themePath.getAbsolutePath());
|
||||||
logsService.saveByLogs(
|
logsService.save(LogsRecord.UPLOAD_THEME, file.getOriginalFilename(), request);
|
||||||
new Logs(LogsRecord.UPLOAD_THEME, file.getOriginalFilename(), ServletUtil.getClientIP(request), DateUtil.date())
|
|
||||||
);
|
|
||||||
ZipUtil.unzip(themePath, new File(basePath.getAbsolutePath(), "templates/themes/"));
|
ZipUtil.unzip(themePath, new File(basePath.getAbsolutePath(), "templates/themes/"));
|
||||||
FileUtil.del(themePath);
|
FileUtil.del(themePath);
|
||||||
HaloConst.THEMES.clear();
|
HaloConst.THEMES.clear();
|
||||||
|
|
|
@ -75,6 +75,7 @@ public class ApiPostController {
|
||||||
public JsonResult posts(@PathVariable(value = "postId") Long postId) {
|
public JsonResult posts(@PathVariable(value = "postId") Long postId) {
|
||||||
Post post = postService.findByPostId(postId, PostTypeEnum.POST_TYPE_POST.getDesc());
|
Post post = postService.findByPostId(postId, PostTypeEnum.POST_TYPE_POST.getDesc());
|
||||||
if (null != post) {
|
if (null != post) {
|
||||||
|
postService.cacheViews(post.getPostId());
|
||||||
return new JsonResult(ResponseStatusEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), post);
|
return new JsonResult(ResponseStatusEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), post);
|
||||||
} else {
|
} else {
|
||||||
return new JsonResult(ResponseStatusEnum.NOTFOUND.getCode(), ResponseStatusEnum.NOTFOUND.getMsg());
|
return new JsonResult(ResponseStatusEnum.NOTFOUND.getCode(), ResponseStatusEnum.NOTFOUND.getMsg());
|
||||||
|
|
|
@ -11,7 +11,6 @@ import cc.ryanc.halo.utils.MarkdownUtils;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.crypto.SecureUtil;
|
import cn.hutool.crypto.SecureUtil;
|
||||||
import cn.hutool.extra.servlet.ServletUtil;
|
|
||||||
import freemarker.template.Configuration;
|
import freemarker.template.Configuration;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -160,7 +159,7 @@ public class InstallController {
|
||||||
optionsService.saveOption(BlogPropertiesEnum.IS_INSTALL.getProp(), TrueFalseEnum.TRUE.getDesc());
|
optionsService.saveOption(BlogPropertiesEnum.IS_INSTALL.getProp(), TrueFalseEnum.TRUE.getDesc());
|
||||||
|
|
||||||
//语言设置
|
//语言设置
|
||||||
optionsService.saveOption(BlogPropertiesEnum.BLOG_LOCALE.getProp(),blogLocale);
|
optionsService.saveOption(BlogPropertiesEnum.BLOG_LOCALE.getProp(), blogLocale);
|
||||||
//保存博客标题和博客地址设置
|
//保存博客标题和博客地址设置
|
||||||
optionsService.saveOption(BlogPropertiesEnum.BLOG_TITLE.getProp(), blogTitle);
|
optionsService.saveOption(BlogPropertiesEnum.BLOG_TITLE.getProp(), blogTitle);
|
||||||
optionsService.saveOption(BlogPropertiesEnum.BLOG_URL.getProp(), blogUrl);
|
optionsService.saveOption(BlogPropertiesEnum.BLOG_URL.getProp(), blogUrl);
|
||||||
|
@ -169,7 +168,7 @@ public class InstallController {
|
||||||
optionsService.saveOption(BlogPropertiesEnum.THEME.getProp(), "anatole");
|
optionsService.saveOption(BlogPropertiesEnum.THEME.getProp(), "anatole");
|
||||||
|
|
||||||
//建立网站时间
|
//建立网站时间
|
||||||
optionsService.saveOption(BlogPropertiesEnum.BLOG_START.getProp(), DateUtil.format(DateUtil.date(),"yyyy-MM-dd"));
|
optionsService.saveOption(BlogPropertiesEnum.BLOG_START.getProp(), DateUtil.format(DateUtil.date(), "yyyy-MM-dd"));
|
||||||
|
|
||||||
//默认不配置邮件系统
|
//默认不配置邮件系统
|
||||||
optionsService.saveOption(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp(), TrueFalseEnum.FALSE.getDesc());
|
optionsService.saveOption(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp(), TrueFalseEnum.FALSE.getDesc());
|
||||||
|
@ -180,14 +179,7 @@ public class InstallController {
|
||||||
optionsService.saveOption(BlogPropertiesEnum.COMMENT_REPLY_NOTICE.getProp(), TrueFalseEnum.FALSE.getDesc());
|
optionsService.saveOption(BlogPropertiesEnum.COMMENT_REPLY_NOTICE.getProp(), TrueFalseEnum.FALSE.getDesc());
|
||||||
|
|
||||||
//更新日志
|
//更新日志
|
||||||
logsService.saveByLogs(
|
logsService.save(LogsRecord.INSTALL, "安装成功,欢迎使用Halo。", request);
|
||||||
new Logs(
|
|
||||||
LogsRecord.INSTALL,
|
|
||||||
"安装成功,欢迎使用Halo。",
|
|
||||||
ServletUtil.getClientIP(request),
|
|
||||||
DateUtil.date()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
Menu menuIndex = new Menu();
|
Menu menuIndex = new Menu();
|
||||||
menuIndex.setMenuName("首页");
|
menuIndex.setMenuName("首页");
|
||||||
|
|
Loading…
Reference in New Issue