mirror of
https://github.com/eiblog/eiblog.git
synced 2026-02-07 07:12:27 +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) {
|
||||
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)
|
||||
}
|
||||
|
||||
4
check.go
4
check.go
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user