fix post-add bug

This commit is contained in:
deepzz0
2016-12-18 01:14:47 +08:00
parent 5f73a30d37
commit 3254ff89b0
3 changed files with 21 additions and 19 deletions

34
api.go
View File

@@ -161,24 +161,31 @@ func apiPostDelete(c *gin.Context) {
func apiPostAdd(c *gin.Context) {
var err error
var publish bool
var do string
var cid int
defer func() {
if !publish {
if err == nil {
c.JSON(http.StatusOK, gin.H{"success": SUCCESS, "time": time.Now().Format("15:04:05 PM"), "cid": cid})
} else {
logd.Error(err)
switch do {
case "auto": // 自动保存
if err != nil {
c.JSON(http.StatusOK, gin.H{"fail": FAIL, "time": time.Now().Format("15:04:05 PM"), "cid": cid})
return
}
c.JSON(http.StatusOK, gin.H{"success": SUCCESS, "time": time.Now().Format("15:04:05 PM"), "cid": cid})
case "save": // 保存草稿
if err != nil {
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
return
}
c.Redirect(http.StatusFound, "/admin/manage-draft")
case "publish": // 发布
if err != nil {
responseNotice(c, NOTICE_NOTICE, err.Error(), "")
return
}
}
if err == nil {
c.Redirect(http.StatusFound, "/admin/manage-posts")
return
}
logd.Error(err)
}()
do := c.PostForm("do") // save or publish
do = c.PostForm("do") // auto or save or publish
slug := c.PostForm("slug")
title := c.PostForm("title")
text := c.PostForm("text")
@@ -195,13 +202,12 @@ func apiPostAdd(c *gin.Context) {
tags = strings.Split(tag, ",")
}
serieid := CheckSerieID(serie)
publish = CheckPublish(do)
artc := &Article{
Title: title,
Content: text,
Slug: slug,
CreateTime: CheckDate(date),
IsDraft: !publish,
IsDraft: do != "publish",
Author: Ei.Username,
SerieID: serieid,
Tags: tags,
@@ -214,7 +220,7 @@ func apiPostAdd(c *gin.Context) {
return
}
cid = int(artc.ID)
if publish {
if !artc.IsDraft {
ElasticIndex(artc)
DoPings(slug)
}

View File

@@ -42,7 +42,3 @@ func CheckSerieID(sid string) int32 {
func CheckBool(str string) bool {
return str == "true" || str == "1"
}
func CheckPublish(do string) bool {
return do == "publish"
}

View File

@@ -271,7 +271,7 @@ $(document).ready(function() {
locked = true;
autoSave.text('正在保存');
$.post(formAction, data + '&do=save', function(o) {
$.post(formAction, data + '&do=auto', function(o) {
savedData = data;
lastSaveTime = o.time;
cid = o.cid;