Skip to content

Commit

Permalink
update blade to 2x
Browse files Browse the repository at this point in the history
  • Loading branch information
hellokaton committed Jun 3, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 19db795 commit 47ad4f7
Showing 36 changed files with 321 additions and 465 deletions.
15 changes: 0 additions & 15 deletions contribution.md

This file was deleted.

24 changes: 0 additions & 24 deletions donate.md

This file was deleted.

13 changes: 4 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -11,17 +11,17 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sqlite.version>3.15.1</sqlite.version>
<blade.version>1.7.2-alpha</blade.version>
<blade.version>2.0.0-SNAPSHOT</blade.version>
<blade-jdbc.version>0.1.6-beta</blade-jdbc.version>
<blade-tpl.verion>0.0.9</blade-tpl.verion>
<blade-tpl.verion>0.1.0</blade-tpl.verion>
<blade-embed-jetty.version>0.1.3</blade-embed-jetty.version>
</properties>

<dependencies>
<!-- mvc -->
<dependency>
<groupId>com.bladejava</groupId>
<artifactId>blade-core</artifactId>
<artifactId>blade-mvc</artifactId>
<version>${blade.version}</version>
</dependency>

@@ -55,12 +55,7 @@
<artifactId>commonmark-ext-gfm-tables</artifactId>
<version>0.8.0</version>
</dependency>
<!--web容器-->
<dependency>
<groupId>com.bladejava</groupId>
<artifactId>blade-embed-jetty</artifactId>
<version>${blade-embed-jetty.version}</version>
</dependency>

<!--RSS输出-->
<dependency>
<groupId>rome</groupId>
8 changes: 4 additions & 4 deletions src/main/java/com/tale/Application.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.tale;

import com.blade.Blade;
import com.tale.init.TaleLoader;

import static com.blade.Blade.$;

public class Application {

public static void main(String[] args) throws Exception {
TaleLoader.init();
$().start(Application.class);
Blade blade = Blade.me();
TaleLoader.init(blade);
blade.start(Application.class, args);
}

}
39 changes: 20 additions & 19 deletions src/main/java/com/tale/controller/IndexController.java
Original file line number Diff line number Diff line change
@@ -3,15 +3,15 @@
import com.blade.ioc.annotation.Inject;
import com.blade.jdbc.core.Take;
import com.blade.jdbc.model.Paginator;
import com.blade.kit.IPKit;
import com.blade.kit.PatternKit;
import com.blade.kit.StringKit;
import com.blade.mvc.Const;
import com.blade.mvc.annotation.*;
import com.blade.mvc.http.HttpMethod;
import com.blade.mvc.http.Request;
import com.blade.mvc.http.Response;
import com.blade.mvc.http.wrapper.Session;
import com.blade.mvc.view.RestResponse;
import com.blade.mvc.http.Session;
import com.blade.mvc.ui.RestResponse;
import com.tale.dto.Archive;
import com.tale.dto.ErrorCode;
import com.tale.dto.MetaDto;
@@ -34,7 +34,7 @@
import java.net.URLEncoder;
import java.util.List;

@Controller
@Path
public class IndexController extends BaseController {

private static final Logger LOGGER = LoggerFactory.getLogger(IndexController.class);
@@ -56,8 +56,8 @@ public class IndexController extends BaseController {
*
* @return
*/
@Route(value = "/", method = HttpMethod.GET)
public String index(Request request, @QueryParam(value = "limit", defaultValue = "12") int limit) {
@Route(values = "/", method = HttpMethod.GET)
public String index(Request request, @QueryParam(defaultValue = "12") int limit) {
return this.index(request, 1, limit);
}

@@ -94,7 +94,7 @@ public String page(@PathParam String cid, Request request) {
* @return
*/
@Route(values = {"page/:page", "page/:page.html"}, method = HttpMethod.GET)
public String index(Request request, @PathParam int page, @QueryParam(value = "limit", defaultValue = "12") int limit) {
public String index(Request request, @PathParam int page, @QueryParam(defaultValue = "12") int limit) {
page = page < 0 || page > TaleConst.MAX_PAGE ? 1 : page;
Take take = new Take(Contents.class).eq("type", Types.ARTICLE).eq("status", Types.PUBLISH).page(page, limit, "created desc");
Paginator<Contents> articles = contentsService.getArticles(take);
@@ -146,13 +146,13 @@ private void updateArticleHit(Integer cid, Integer chits) {
* @return
*/
@Route(values = {"category/:keyword", "category/:keyword.html"}, method = HttpMethod.GET)
public String categories(Request request, @PathParam String keyword, @QueryParam(value = "limit", defaultValue = "12") int limit) {
public String categories(Request request, @PathParam String keyword, @QueryParam(defaultValue = "12") int limit) {
return this.categories(request, keyword, 1, limit);
}

@Route(values = {"category/:keyword/:page", "category/:keyword/:page.html"}, method = HttpMethod.GET)
public String categories(Request request, @PathParam String keyword,
@PathParam int page, @QueryParam(value = "limit", defaultValue = "12") int limit) {
@PathParam int page, @QueryParam(defaultValue = "12") int limit) {
page = page < 0 || page > TaleConst.MAX_PAGE ? 1 : page;
MetaDto metaDto = metasService.getMeta(Types.CATEGORY, keyword);
if (null == metaDto) {
@@ -178,7 +178,7 @@ public String categories(Request request, @PathParam String keyword,
* @return
*/
@Route(values = {"tag/:name", "tag/:name.html"}, method = HttpMethod.GET)
public String tags(Request request, @PathParam String name, @QueryParam(value = "limit", defaultValue = "12") int limit) {
public String tags(Request request, @PathParam String name, @QueryParam(defaultValue = "12") int limit) {
return this.tags(request, name, 1, limit);
}

@@ -192,7 +192,7 @@ public String tags(Request request, @PathParam String name, @QueryParam(value =
* @return
*/
@Route(values = {"tag/:name/:page", "tag/:name/:page.html"}, method = HttpMethod.GET)
public String tags(Request request, @PathParam String name, @PathParam int page, @QueryParam(value = "limit", defaultValue = "12") int limit) {
public String tags(Request request, @PathParam String name, @PathParam int page, @QueryParam(defaultValue = "12") int limit) {

page = page < 0 || page > TaleConst.MAX_PAGE ? 1 : page;
MetaDto metaDto = metasService.getMeta(Types.TAG, name);
@@ -218,18 +218,18 @@ public String tags(Request request, @PathParam String name, @PathParam int page,
* @return
*/
@Route(values = {"search/:keyword", "search/:keyword.html"}, method = HttpMethod.GET)
public String search(Request request, @PathParam String keyword, @QueryParam(value = "limit", defaultValue = "12") int limit) {
public String search(Request request, @PathParam String keyword, @QueryParam(defaultValue = "12") int limit) {
return this.search(request, keyword, 1, limit);
}

@Route(values = {"search", "search.html"})
public String search(Request request, @QueryParam(value = "limit", defaultValue = "12") int limit) {
String keyword = request.query("s");
public String search(Request request, @QueryParam(defaultValue = "12") int limit) {
String keyword = request.query("s").orElse("");
return this.search(request, keyword, 1, limit);
}

@Route(values = {"search/:keyword/:page", "search/:keyword/:page.html"}, method = HttpMethod.GET)
public String search(Request request, @PathParam String keyword, @PathParam int page, @QueryParam(value = "limit", defaultValue = "12") int limit) {
public String search(Request request, @PathParam String keyword, @PathParam int page, @QueryParam(defaultValue = "12") int limit) {

page = page < 0 || page > TaleConst.MAX_PAGE ? 1 : page;
Take take = new Take(Contents.class).eq("type", Types.ARTICLE).eq("status", Types.PUBLISH)
@@ -280,7 +280,8 @@ public void feed(Response response) {
.eq("type", Types.ARTICLE).eq("status", Types.PUBLISH).eq("allow_feed", true).page(1, TaleConst.MAX_POSTS, "created desc"));
try {
String xml = TaleUtils.getRssXml(contentsPaginator.getList());
response.xml(xml);
response.contentType(Const.CONTENT_TYPE_XML);
response.body(xml);
} catch (Exception e) {
LOGGER.error("生成RSS失败", e);
}
@@ -292,15 +293,15 @@ public void feed(Response response) {
* @param session
* @param response
*/
@Route("logout")
@Route(values = "logout")
public void logout(Session session, Response response) {
TaleUtils.logout(session, response);
}

/**
* 评论操作
*/
@Route(value = "comment", method = HttpMethod.POST)
@Route(values = "comment", method = HttpMethod.POST)
@JSON
public RestResponse comment(Request request, Response response,
@QueryParam Integer cid, @QueryParam Integer coid,
@@ -341,7 +342,7 @@ public RestResponse comment(Request request, Response response,
return RestResponse.fail("请输入200个字符以内的评论");
}

String val = IPKit.getIpAddrByRequest(request.raw()) + ":" + cid;
String val = request.address() + ":" + cid;
Integer count = cache.hget(Types.COMMENTS_FREQUENCY, val);
if (null != count && count > 0) {
return RestResponse.fail("您发表评论太快了,请过会再试");
28 changes: 14 additions & 14 deletions src/main/java/com/tale/controller/InstallController.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package com.tale.controller;


import com.blade.Environment;
import com.blade.ioc.annotation.Inject;
import com.blade.kit.FileKit;
import com.blade.kit.StringKit;
import com.blade.kit.base.Config;
import com.blade.mvc.annotation.Controller;
import com.blade.mvc.annotation.JSON;
import com.blade.mvc.annotation.Path;
import com.blade.mvc.annotation.QueryParam;
import com.blade.mvc.annotation.Route;
import com.blade.mvc.http.HttpMethod;
import com.blade.mvc.http.Request;
import com.blade.mvc.view.RestResponse;
import com.blade.mvc.ui.RestResponse;
import com.tale.controller.admin.AttachController;
import com.tale.exception.TipException;
import com.tale.init.TaleConst;
@@ -22,7 +21,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Controller("install")
import java.nio.file.Files;
import java.nio.file.Paths;

@Path("install")
public class InstallController extends BaseController {

private static final Logger LOGGER = LoggerFactory.getLogger(InstallController.class);
@@ -38,26 +40,26 @@ public class InstallController extends BaseController {
*
* @return
*/
@Route(value = "/", method = HttpMethod.GET)
@Route(values = "/", method = HttpMethod.GET)
public String index(Request request) {
boolean existInstall = FileKit.exist(AttachController.CLASSPATH + "install.lock");
boolean existInstall = Files.exists(Paths.get(AttachController.CLASSPATH + "install.lock"));
int allow_reinstall = TaleConst.OPTIONS.getInt("allow_install", 0);

if(allow_reinstall == 1){
if (allow_reinstall == 1) {
request.attribute("is_install", false);
} else {
request.attribute("is_install", existInstall);
}
return "install";
}

@Route(value = "/", method = HttpMethod.POST)
@Route(values = "/", method = HttpMethod.POST)
@JSON
public RestResponse doInstall(@QueryParam String site_title, @QueryParam String site_url,
@QueryParam String admin_user, @QueryParam String admin_email,
@QueryParam String admin_pwd) {
if(FileKit.exist(AttachController.CLASSPATH + "install.lock")
&& TaleConst.OPTIONS.getInt("allow_install", 0)!=1){
if (Files.exists(Paths.get(AttachController.CLASSPATH + "install.lock"))
&& TaleConst.OPTIONS.getInt("allow_install", 0) != 1) {
return RestResponse.fail("请勿重复安装");
}
try {
@@ -92,9 +94,7 @@ public RestResponse doInstall(@QueryParam String site_title, @QueryParam String
optionsService.saveOption("site_title", site_title);
optionsService.saveOption("site_url", site_url);

Config config = new Config();
config.addAll(optionsService.getOptions());
TaleConst.OPTIONS = config;
TaleConst.OPTIONS = Environment.of(optionsService.getOptions());
} catch (Exception e) {
String msg = "安装失败";
if (e instanceof TipException) {
23 changes: 11 additions & 12 deletions src/main/java/com/tale/controller/admin/ArticleController.java
Original file line number Diff line number Diff line change
@@ -5,9 +5,8 @@
import com.blade.jdbc.model.Paginator;
import com.blade.kit.StringKit;
import com.blade.mvc.annotation.*;
import com.blade.mvc.http.HttpMethod;
import com.blade.mvc.http.Request;
import com.blade.mvc.view.RestResponse;
import com.blade.mvc.ui.RestResponse;
import com.tale.controller.BaseController;
import com.tale.dto.LogActions;
import com.tale.dto.Types;
@@ -29,7 +28,7 @@
* 文章管理控制器
* Created by biezhi on 2017/2/21.
*/
@Controller("admin/article")
@Path("admin/article")
public class ArticleController extends BaseController {

private static final Logger LOGGER = LoggerFactory.getLogger(ArticleController.class);
@@ -53,9 +52,9 @@ public class ArticleController extends BaseController {
* @param request
* @return
*/
@Route(value = "", method = HttpMethod.GET)
public String index(@QueryParam(value = "page", defaultValue = "1") int page,
@QueryParam(value = "limit", defaultValue = "15") int limit, Request request) {
@GetRoute(values = "")
public String index(@QueryParam(defaultValue = "1") int page,
@QueryParam(defaultValue = "15") int limit, Request request) {

Paginator<Contents> contentsPaginator = contentsService.getArticles(new Take(Contents.class).eq("type", Types.ARTICLE).page(page, limit, "created desc"));
request.attribute("articles", contentsPaginator);
@@ -67,7 +66,7 @@ public String index(@QueryParam(value = "page", defaultValue = "1") int page,
* @param request
* @return
*/
@Route(value = "publish", method = HttpMethod.GET)
@GetRoute(values = "publish")
public String newArticle(Request request) {
List<Metas> categories = metasService.getMetas(Types.CATEGORY);
request.attribute("categories", categories);
@@ -81,7 +80,7 @@ public String newArticle(Request request) {
* @param request
* @return
*/
@Route(value = "/:cid", method = HttpMethod.GET)
@GetRoute(values = "/:cid")
public String editArticle(@PathParam String cid, Request request) {
Contents contents = contentsService.getContents(cid);
request.attribute("contents", contents);
@@ -106,12 +105,12 @@ public String editArticle(@PathParam String cid, Request request) {
* @param allow_feed
* @return
*/
@Route(value = "publish", method = HttpMethod.POST)
@PostRoute(values = "publish")
@JSON
public RestResponse publishArticle(@QueryParam String title, @QueryParam String content,
@QueryParam String tags, @QueryParam String categories,
@QueryParam String status, @QueryParam String slug,
@QueryParam String fmt_type,@QueryParam String thumb_img,
@QueryParam String fmt_type, @QueryParam String thumb_img,
@QueryParam Boolean allow_comment, @QueryParam Boolean allow_ping, @QueryParam Boolean allow_feed) {

Users users = this.user();
@@ -170,7 +169,7 @@ public RestResponse publishArticle(@QueryParam String title, @QueryParam String
* @param allow_feed
* @return
*/
@Route(value = "modify", method = HttpMethod.POST)
@PostRoute(values = "modify")
@JSON
public RestResponse modifyArticle(@QueryParam Integer cid, @QueryParam String title,
@QueryParam String content,@QueryParam String fmt_type,
@@ -221,7 +220,7 @@ public RestResponse modifyArticle(@QueryParam Integer cid, @QueryParam String ti
* @param request
* @return
*/
@Route(value = "delete")
@Route(values = "delete")
@JSON
public RestResponse delete(@QueryParam int cid, Request request) {
try {
Loading

0 comments on commit 47ad4f7

Please sign in to comment.