mirror of https://github.com/halo-dev/halo
修复保存带html后缀路径的问题
具体表现为: 新建文章时, "永久链接"以.html或者.htm结尾, 可以保存, 查看时ControllerNPEpull/8/head
parent
b9023a7b26
commit
2d1143389e
|
@ -176,6 +176,7 @@ public class PostController extends BaseController{
|
|||
List<Tag> tags = tagService.strListToTagList(StringUtils.trim(tagList));
|
||||
post.setTags(tags);
|
||||
}
|
||||
post.setPostUrl(urlFilter(post.getPostUrl()));
|
||||
postService.saveByPost(post);
|
||||
logsService.saveByLogs(new Logs(LogsRecord.PUSH_POST,post.getPostTitle(),HaloUtil.getIpAddr(request),HaloUtil.getDate()));
|
||||
}catch (Exception e){
|
||||
|
@ -183,6 +184,17 @@ public class PostController extends BaseController{
|
|||
}
|
||||
}
|
||||
|
||||
private static String urlFilter(String url) {
|
||||
if (null != url) {
|
||||
final boolean urlEndsWithHtmlPostFix = url.endsWith(".html") || url.endsWith(".htm");
|
||||
if (urlEndsWithHtmlPostFix) {
|
||||
return url.substring(0, url.lastIndexOf("."));
|
||||
}
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理移至回收站的请求
|
||||
*
|
||||
|
@ -282,6 +294,7 @@ public class PostController extends BaseController{
|
|||
@GetMapping(value = "/checkUrl")
|
||||
@ResponseBody
|
||||
public boolean checkUrlExists(@PathParam("postUrl") String postUrl){
|
||||
postUrl = urlFilter(postUrl);
|
||||
Post post = postService.findByPostUrl(postUrl,HaloConst.POST_TYPE_POST);
|
||||
return null!=post;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue