Skip to content

Commit

Permalink
Merge pull request otale#4 from otale/develop
Browse files Browse the repository at this point in the history
merge master
  • Loading branch information
dongm2ez authored Oct 15, 2018
2 parents 675e8aa + 440baaf commit 270b9bc
Show file tree
Hide file tree
Showing 60 changed files with 544 additions and 11,066 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ logs/

# database file #
tale.db
pack.sh
154 changes: 154 additions & 0 deletions bin/tool
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
#!/bin/sh

APP_NAME="tale"
JAVA_OPTS="-Xms256m -Xmx256m -Dfile.encoding=UTF-8"
psid=0

checkpid() {
javaps=$(pgrep -f "tale-latest")

if [ -n "$javaps" ]; then
psid=$javaps
else
psid=0
fi
}

start() {
checkpid

if [ $psid -ne 0 ]; then
echo "================================"
echo "warn: $APP_NAME already started! (pid=$psid)"
echo "================================"
else
echo "Starting $APP_NAME ..."
nohup java $JAVA_OPTS -jar tale-latest.jar --app.env=prod >/dev/null 2>&1 &
sleep 1
checkpid
if [ $psid -ne 0 ]; then
echo "(pid=$psid) [OK]"
else
echo "[Failed]"
fi
fi
}

stop() {
checkpid

if [ $psid -ne 0 ]; then
echo -n "Stopping $APP_NAME ...(pid=$psid) "
kill -9 $psid

if [ $? -eq 0 ]; then
echo "[OK]"
else
echo "[Failed]"
fi

checkpid
if [ $psid -ne 0 ]; then
stop
fi
else
echo "================================"
echo "warn: $APP_NAME is not running"
echo "================================"
fi
}

status() {
checkpid
if [ $psid -ne 0 ]; then
echo "$APP_NAME is running! (pid=$psid)"
else
echo "$APP_NAME is not running"
fi
}

showlog() {
tail -f logs/tale.log
}

get_latest_release() {
curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api
grep '"tag_name":' | # Get tag line
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
}

REMOVE_LOCAL_THEME=1

upgrade(){
echo "是否允许覆盖本地主题 (y/n)?"
read con
case $con in
y|yes|Y|YES)
REMOVE_THEME=1
;;
*)
break
;;
esac

# 备份当前目录
TIME=`date +%Y%m%d_%H%m`
tar czvf back_$TIME.tar.gz *
echo '备份成功'

echo '开始下载最新版本.'

TAG_VERSION=$(get_latest_release "otale/tale")
wget -N --no-check-certificate https://github.com/otale/tale/releases/download/$TAG_VERSION/tale.tar.gz

mkdir upgrade_tmp
tar -zxvf $APP_NAME.tar.gz -C upgrade_tmp
sh tool stop
rm -rf lib tale-latest.jar tool resources/static resources/templates/admin resources/templates/comm resources/templates/*.html resources/*.properties

if [ "$REMOVE_LOCAL_THEME" -eq "1" ]; then
rm -rf resources/templates/themes
mv upgrade_tmp/resources/templates/themes resources/templates
fi

mv upgrade_tmp/lib .
mv upgrade_tmp/tale-latest.jar .
mv upgrade_tmp/tool .
chmod +x tool
mv upgrade_tmp/resources/static ./resources
mv upgrade_tmp/resources/*.properties ./resources
mv upgrade_tmp/resources/templates/admin ./resources/templates
mv upgrade_tmp/resources/templates/comm ./resources/templates
mv upgrade_tmp/resources/templates/*.html ./resources/templates

echo '升级完毕, 请执行 sh tool restart 重启博客系统!'

rm -rf upgrade_tmp
rm -rf tale.tar.gz
}

case "$1" in
'start')
start
;;
'stop')
stop
;;
'restart')
stop
start
;;
'status')
status
;;
'log')
showlog
;;
'upgrade')
upgrade
;;
*)
echo "Usage: $0 {start | stop | restart | status | upgrade | log}"
exit 1
esac
exit 0
20 changes: 20 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

APP_NAME="tale"
get_latest_release() {
curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api
grep '"tag_name":' | # Get tag line
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
}

TAG_VERSION=$(get_latest_release "otale/tale")

wget -N --no-check-certificate https://github.com/otale/tale/releases/download/$TAG_VERSION/tale.tar.gz

echo '下载完毕'

mkdir $APP_NAME
tar -zxvf $APP_NAME.tar.gz -C $APP_NAME && cd $APP_NAME
chmod +x tool

echo '安装成功,请进入 tale 目录执行 sh tool start 启动'
3 changes: 0 additions & 3 deletions package.sh

This file was deleted.

10 changes: 7 additions & 3 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">

<id>customAssembly</id>
<!-- dir -->
<id>bin</id>
<formats>
<format>dir</format>
<format>tar.gz</format>
<format>zip</format>
</formats>

<includeBaseDirectory>false</includeBaseDirectory>
Expand All @@ -19,6 +19,10 @@
<directory>src/main/plugins/</directory>
<outputDirectory>/plugins</outputDirectory>
</fileSet>
<fileSet>
<directory>bin/</directory>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>

<dependencySets>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sqlite.version>3.21.0.1</sqlite.version>
<blade-mvc.version>2.0.9.BETA3</blade-mvc.version>
<anima.version>0.2.3</anima.version>
<blade-mvc.version>2.0.10.RELEASE</blade-mvc.version>
<anima.version>0.2.4</anima.version>
<blade-tpl.verion>0.1.3</blade-tpl.verion>
<commonmark.version>0.11.0</commonmark.version>
<rome.version>1.0</rome.version>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/tale/bootstrap/TaleConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,5 @@ public class TaleConst {
public static final String OPTION_SITE_THEME = "site_theme";
public static final String OPTION_ALLOW_INSTALL = "allow_install";
public static final String OPTION_ALLOW_COMMENT_AUDIT = "allow_comment_audit";
public static final String OPTION_ALLOW_CLOUD_CDN = "allow_cloud_CDN";
}
2 changes: 1 addition & 1 deletion src/main/java/com/tale/controller/ArticleController.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public RestResponse<?> comment(Request request, Response response,

// 设置对每个文章30秒可以评论一次
cache.hset(Types.COMMENTS_FREQUENCY, val, 1, 30);
siteService.cleanCache(Types.C_STATISTICS);
siteService.cleanCache(Types.SYS_STATISTICS);

return RestResponse.ok();
} catch (Exception e) {
Expand Down
48 changes: 35 additions & 13 deletions src/main/java/com/tale/controller/admin/AdminApiController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.tale.controller.admin;

import com.blade.Blade;
import com.blade.Environment;
import com.blade.ioc.annotation.Inject;
import com.blade.kit.JsonKit;
Expand All @@ -9,6 +8,7 @@
import com.blade.mvc.WebContext;
import com.blade.mvc.annotation.*;
import com.blade.mvc.http.Request;
import com.blade.mvc.http.Response;
import com.blade.mvc.ui.RestResponse;
import com.tale.annotation.SysLog;
import com.tale.bootstrap.TaleConst;
Expand Down Expand Up @@ -64,12 +64,27 @@ public RestResponse sysLogs(PageParam pageParam) {
return RestResponse.ok(select().from(Logs.class).order(Logs::getId, OrderBy.DESC).page(pageParam.getPage(), pageParam.getLimit()));
}

@SysLog("删除页面")
@PostRoute("page/delete/:cid")
public RestResponse<?> deletePage(@PathParam Integer cid) {
contentsService.delete(cid);
siteService.cleanCache(Types.SYS_STATISTICS);
return RestResponse.ok();
}

@GetRoute("articles/:cid")
public RestResponse article(@PathParam String cid) {
Contents contents = contentsService.getContents(cid);
contents.setContent("");
return RestResponse.ok(contents);
}

@GetRoute("articles/content/:cid")
public void articleContent(@PathParam String cid, Response response) {
Contents contents = contentsService.getContents(cid);
response.text(contents.getContent());
}

@PostRoute("article/new")
public RestResponse newArticle(@BodyParam Contents contents) {
CommonValidator.valid(contents);
Expand All @@ -85,14 +100,14 @@ public RestResponse newArticle(@BodyParam Contents contents) {
contents.setCategories("默认分类");
}
Integer cid = contentsService.publish(contents);
siteService.cleanCache(Types.C_STATISTICS);
siteService.cleanCache(Types.SYS_STATISTICS);
return RestResponse.ok(cid);
}

@PostRoute("article/delete/:cid")
public RestResponse<?> deleteArticle(@PathParam Integer cid) {
contentsService.delete(cid);
siteService.cleanCache(Types.C_STATISTICS);
siteService.cleanCache(Types.SYS_STATISTICS);
return RestResponse.ok();
}

Expand Down Expand Up @@ -134,7 +149,7 @@ public RestResponse<?> newPage(@BodyParam Contents contents) {
contents.setAllowPing(true);
contents.setAuthorId(users.getUid());
contentsService.publish(contents);
siteService.cleanCache(Types.C_STATISTICS);
siteService.cleanCache(Types.SYS_STATISTICS);
return RestResponse.ok();
}

Expand Down Expand Up @@ -162,15 +177,15 @@ public RestResponse categories() {
@PostRoute("category/save")
public RestResponse<?> saveCategory(@BodyParam MetaParam metaParam) {
metasService.saveMeta(Types.CATEGORY, metaParam.getCname(), metaParam.getMid());
siteService.cleanCache(Types.C_STATISTICS);
siteService.cleanCache(Types.SYS_STATISTICS);
return RestResponse.ok();
}

@SysLog("删除分类/标签")
@PostRoute("category/delete/:mid")
public RestResponse<?> deleteMeta(@PathParam Integer mid) {
metasService.delete(mid);
siteService.cleanCache(Types.C_STATISTICS);
siteService.cleanCache(Types.SYS_STATISTICS);
return RestResponse.ok();
}

Expand All @@ -191,15 +206,15 @@ public RestResponse<?> deleteComment(@PathParam Integer coid) {
return RestResponse.fail("不存在该评论");
}
commentsService.delete(coid, comments.getCid());
siteService.cleanCache(Types.C_STATISTICS);
siteService.cleanCache(Types.SYS_STATISTICS);
return RestResponse.ok();
}

@SysLog("修改评论状态")
@PostRoute("comment/status")
public RestResponse<?> updateStatus(@BodyParam Comments comments) {
comments.update();
siteService.cleanCache(Types.C_STATISTICS);
siteService.cleanCache(Types.SYS_STATISTICS);
return RestResponse.ok();
}

Expand Down Expand Up @@ -227,7 +242,7 @@ public RestResponse<?> replyComment(@BodyParam Comments comments, Request reques
comments.setStatus(TaleConst.COMMENT_APPROVED);
comments.setParent(comments.getCoid());
commentsService.saveComment(comments);
siteService.cleanCache(Types.C_STATISTICS);
siteService.cleanCache(Types.SYS_STATISTICS);
return RestResponse.ok();
}

Expand All @@ -249,7 +264,7 @@ public RestResponse<?> deleteAttach(@PathParam Integer id) throws IOException {
return RestResponse.fail("不存在该附件");
}
String key = attach.getFkey();
siteService.cleanCache(Types.C_STATISTICS);
siteService.cleanCache(Types.SYS_STATISTICS);
String filePath = CLASSPATH.substring(0, CLASSPATH.length() - 1) + key;
java.nio.file.Path path = Paths.get(filePath);
log.info("Delete attach: [{}]", filePath);
Expand Down Expand Up @@ -335,6 +350,12 @@ public RestResponse<?> saveAdvance(AdvanceParam advanceParam) {
optionsService.saveOption(OPTION_ALLOW_COMMENT_AUDIT, advanceParam.getAllowCommentAudit());
TaleConst.OPTIONS.set(OPTION_ALLOW_COMMENT_AUDIT, advanceParam.getAllowCommentAudit());
}

// 是否允许公共资源CDN
if (StringKit.isNotBlank(advanceParam.getAllowCloudCDN())) {
optionsService.saveOption(OPTION_ALLOW_CLOUD_CDN, advanceParam.getAllowCloudCDN());
TaleConst.OPTIONS.set(OPTION_ALLOW_CLOUD_CDN, advanceParam.getAllowCloudCDN());
}
return RestResponse.ok();
}

Expand Down Expand Up @@ -397,12 +418,13 @@ public RestResponse<?> activeTheme(@BodyParam ThemeParam themeParam) {

@SysLog("保存模板")
@PostRoute("template/save")
public RestResponse<?> saveTpl(@Param String fileName, @Param String content) throws IOException {
if (StringKit.isBlank(fileName)) {
public RestResponse<?> saveTpl(@BodyParam TemplateParam templateParam) throws IOException {
if (StringKit.isBlank(templateParam.getFileName())) {
return RestResponse.fail("缺少参数,请重试");
}
String content = templateParam.getContent();
String themePath = Const.CLASSPATH + File.separatorChar + "templates" + File.separatorChar + "themes" + File.separatorChar + Commons.site_theme();
String filePath = themePath + File.separatorChar + fileName;
String filePath = themePath + File.separatorChar + templateParam.getFileName();
if (Files.exists(Paths.get(filePath))) {
byte[] rf_wiki_byte = content.getBytes("UTF-8");
Files.write(Paths.get(filePath), rf_wiki_byte);
Expand Down
Loading

0 comments on commit 270b9bc

Please sign in to comment.