mirror of
https://github.com/eiblog/eiblog.git
synced 2026-02-17 03:42:26 +08:00
fix post-add bug
This commit is contained in:
34
api.go
34
api.go
@@ -161,24 +161,31 @@ func apiPostDelete(c *gin.Context) {
|
|||||||
|
|
||||||
func apiPostAdd(c *gin.Context) {
|
func apiPostAdd(c *gin.Context) {
|
||||||
var err error
|
var err error
|
||||||
var publish bool
|
var do string
|
||||||
var cid int
|
var cid int
|
||||||
defer func() {
|
defer func() {
|
||||||
if !publish {
|
switch do {
|
||||||
if err == nil {
|
case "auto": // 自动保存
|
||||||
c.JSON(http.StatusOK, gin.H{"success": SUCCESS, "time": time.Now().Format("15:04:05 PM"), "cid": cid})
|
if err != nil {
|
||||||
} else {
|
|
||||||
logd.Error(err)
|
|
||||||
c.JSON(http.StatusOK, gin.H{"fail": FAIL, "time": time.Now().Format("15:04:05 PM"), "cid": cid})
|
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")
|
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")
|
slug := c.PostForm("slug")
|
||||||
title := c.PostForm("title")
|
title := c.PostForm("title")
|
||||||
text := c.PostForm("text")
|
text := c.PostForm("text")
|
||||||
@@ -195,13 +202,12 @@ func apiPostAdd(c *gin.Context) {
|
|||||||
tags = strings.Split(tag, ",")
|
tags = strings.Split(tag, ",")
|
||||||
}
|
}
|
||||||
serieid := CheckSerieID(serie)
|
serieid := CheckSerieID(serie)
|
||||||
publish = CheckPublish(do)
|
|
||||||
artc := &Article{
|
artc := &Article{
|
||||||
Title: title,
|
Title: title,
|
||||||
Content: text,
|
Content: text,
|
||||||
Slug: slug,
|
Slug: slug,
|
||||||
CreateTime: CheckDate(date),
|
CreateTime: CheckDate(date),
|
||||||
IsDraft: !publish,
|
IsDraft: do != "publish",
|
||||||
Author: Ei.Username,
|
Author: Ei.Username,
|
||||||
SerieID: serieid,
|
SerieID: serieid,
|
||||||
Tags: tags,
|
Tags: tags,
|
||||||
@@ -214,7 +220,7 @@ func apiPostAdd(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
cid = int(artc.ID)
|
cid = int(artc.ID)
|
||||||
if publish {
|
if !artc.IsDraft {
|
||||||
ElasticIndex(artc)
|
ElasticIndex(artc)
|
||||||
DoPings(slug)
|
DoPings(slug)
|
||||||
}
|
}
|
||||||
|
|||||||
4
check.go
4
check.go
@@ -42,7 +42,3 @@ func CheckSerieID(sid string) int32 {
|
|||||||
func CheckBool(str string) bool {
|
func CheckBool(str string) bool {
|
||||||
return str == "true" || str == "1"
|
return str == "true" || str == "1"
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckPublish(do string) bool {
|
|
||||||
return do == "publish"
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ $(document).ready(function() {
|
|||||||
locked = true;
|
locked = true;
|
||||||
|
|
||||||
autoSave.text('正在保存');
|
autoSave.text('正在保存');
|
||||||
$.post(formAction, data + '&do=save', function(o) {
|
$.post(formAction, data + '&do=auto', function(o) {
|
||||||
savedData = data;
|
savedData = data;
|
||||||
lastSaveTime = o.time;
|
lastSaveTime = o.time;
|
||||||
cid = o.cid;
|
cid = o.cid;
|
||||||
|
|||||||
Reference in New Issue
Block a user