mirror of https://github.com/halo-dev/halo
🎨 代码优化
parent
d6495bdc5a
commit
8b4231ec82
|
@ -51,8 +51,10 @@ public class HaloUtils {
|
|||
* @return List
|
||||
*/
|
||||
public static List<BackupDto> getBackUps(String dir) {
|
||||
String srcPathStr = System.getProperties().getProperty("user.home") + "/halo/backup/" + dir;
|
||||
File srcPath = new File(srcPathStr);
|
||||
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<>();
|
||||
BackupDto backupDto = null;
|
||||
|
@ -283,7 +285,7 @@ public class HaloUtils {
|
|||
*
|
||||
* @param posts posts
|
||||
* @return String
|
||||
* @throws FeedException
|
||||
* @throws FeedException FeedException
|
||||
*/
|
||||
public static String getRss(List<Post> posts) throws FeedException {
|
||||
Assert.notEmpty(posts, "posts must not be empty");
|
||||
|
@ -380,13 +382,17 @@ public class HaloUtils {
|
|||
Assert.hasText(token, "token must not be blank");
|
||||
Assert.hasText(urls, "urls must not be blank");
|
||||
|
||||
String url = "http://data.zz.baidu.com/urls?site=" + blogUrl + "&token=" + token;
|
||||
String result = "";
|
||||
StrBuilder url = new StrBuilder("http://data.zz.baidu.com/urls?site=");
|
||||
url.append(blogUrl);
|
||||
url.append("&token=");
|
||||
url.append(token);
|
||||
|
||||
StrBuilder result = new StrBuilder();
|
||||
PrintWriter out = null;
|
||||
BufferedReader in = null;
|
||||
try {
|
||||
// 建立URL之间的连接
|
||||
URLConnection conn = new URL(url).openConnection();
|
||||
URLConnection conn = new URL(url.toString()).openConnection();
|
||||
// 设置通用的请求属性
|
||||
conn.setRequestProperty("Host", "data.zz.baidu.com");
|
||||
conn.setRequestProperty("User-Agent", "curl/7.12.1");
|
||||
|
@ -406,7 +412,7 @@ public class HaloUtils {
|
|||
in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
result += line;
|
||||
result.append(line);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
@ -422,7 +428,7 @@ public class HaloUtils {
|
|||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import cc.ryanc.halo.utils.CommentUtil;
|
|||
import cc.ryanc.halo.utils.OwoUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import cn.hutool.core.text.StrBuilder;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
|
@ -126,8 +127,13 @@ public class FrontCommentController {
|
|||
}
|
||||
if (comment.getCommentParent() > 0) {
|
||||
lastComment = commentService.findCommentById(comment.getCommentParent()).get();
|
||||
String lastContent = "<a href='#comment-id-" + lastComment.getCommentId() + "'>@" + lastComment.getCommentAuthor() + "</a> ";
|
||||
comment.setCommentContent(lastContent + OwoUtil.markToImg(HtmlUtil.escape(comment.getCommentContent()).replace("<br/>", "<br/>")));
|
||||
StrBuilder buildContent = new StrBuilder("<a href='#comment-id-");
|
||||
buildContent.append(lastComment.getCommentId());
|
||||
buildContent.append("'>@");
|
||||
buildContent.append(lastComment.getCommentAuthor());
|
||||
buildContent.append("</a> ");
|
||||
buildContent.append(OwoUtil.markToImg(HtmlUtil.escape(comment.getCommentContent()).replace("<br/>", "<br/>")));
|
||||
comment.setCommentContent(buildContent.toString());
|
||||
} else {
|
||||
//将评论内容的字符专为安全字符
|
||||
comment.setCommentContent(OwoUtil.markToImg(HtmlUtil.escape(comment.getCommentContent()).replace("<br/>", "<br/>")));
|
||||
|
@ -170,13 +176,18 @@ public class FrontCommentController {
|
|||
try {
|
||||
//发送邮件到博主
|
||||
Map<String, Object> map = new HashMap<>(5);
|
||||
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 {
|
||||
pageUrl.append("/p/");
|
||||
}
|
||||
pageUrl.append(post.getPostUrl());
|
||||
pageUrl.append("#comment-id-");
|
||||
pageUrl.append(comment.getCommentId());
|
||||
map.put("pageUrl", pageUrl.toString());
|
||||
map.put("author", userService.findUser().getUserDisplayName());
|
||||
map.put("pageName", post.getPostTitle());
|
||||
if (StrUtil.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) {
|
||||
map.put("pageUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/archives/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId());
|
||||
} else {
|
||||
map.put("pageUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/p/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId());
|
||||
}
|
||||
map.put("visitor", comment.getCommentAuthor());
|
||||
map.put("commentContent", comment.getCommentContent());
|
||||
mailService.sendTemplateMail(userService.findUser().getUserEmail(), "有新的评论", map, "common/mail_template/mail_admin.ftl");
|
||||
|
@ -207,14 +218,20 @@ 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()));
|
||||
if (StrUtil.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) {
|
||||
pageUrl.append("/archives/");
|
||||
|
||||
} else {
|
||||
pageUrl.append("/p/");
|
||||
}
|
||||
pageUrl.append(post.getPostUrl());
|
||||
pageUrl.append("#comment-id-");
|
||||
pageUrl.append(comment.getCommentId());
|
||||
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());
|
||||
if (StrUtil.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) {
|
||||
map.put("pageUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/archives/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId());
|
||||
} else {
|
||||
map.put("pageUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/p/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId());
|
||||
}
|
||||
map.put("commentContent", lastComment.getCommentContent());
|
||||
map.put("replyAuthor", comment.getCommentAuthor());
|
||||
map.put("replyContent", comment.getCommentContent());
|
||||
|
|
Loading…
Reference in New Issue