fix: delete trash article

This commit is contained in:
deepzz0
2021-04-28 14:40:28 +08:00
parent beea4f1746
commit c5a3bd6eab
5 changed files with 144 additions and 97 deletions

View File

@@ -14,10 +14,9 @@ import (
"github.com/eiblog/eiblog/pkg/cache/store"
"github.com/eiblog/eiblog/pkg/config"
"github.com/eiblog/eiblog/pkg/core/blog"
"github.com/eiblog/eiblog/pkg/model"
"github.com/sirupsen/logrus"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)
// baseBEParams 基础参数
@@ -140,11 +139,10 @@ func handleAdminSerie(c *gin.Context) {
id, err := strconv.Atoi(c.Query("mid"))
params["Title"] = "新增专题 | " + cache.Ei.Blogger.BTitle
if err == nil && id > 0 {
var serie *model.Serie
for _, v := range cache.Ei.Series {
if v.ID == id {
params["Title"] = "编辑专题 | " + cache.Ei.Blogger.BTitle
params["Edit"] = serie
params["Edit"] = v
break
}
}
@@ -164,6 +162,21 @@ func handleAdminTags(c *gin.Context) {
renderHTMLAdminLayout(c, "admin-tags", params)
}
// handleDraftDelete 编辑页删除草稿
func handleDraftDelete(c *gin.Context) {
id, err := strconv.Atoi(c.Query("cid"))
if err != nil || id < 1 {
c.JSON(http.StatusBadRequest, gin.H{"error": "参数错误"})
return
}
err = cache.Ei.RemoveArticle(context.Background(), id)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "删除错误"})
return
}
c.Redirect(http.StatusFound, "/admin/write-post")
}
// handleAdminDraft 草稿箱页
func handleAdminDraft(c *gin.Context) {
params := baseBEParams(c)
@@ -202,8 +215,6 @@ func handleAdminTrash(c *gin.Context) {
params["List"], _, err = cache.Ei.LoadArticleList(context.Background(), search)
if err != nil {
logrus.Error("handleTrash.LoadArticleList: ", err)
c.HTML(http.StatusBadRequest, "backLayout.html", params)
return
}
renderHTMLAdminLayout(c, "admin-trash", params)
}

View File

@@ -54,6 +54,7 @@ func RegisterRoutesAuthz(group gin.IRoutes) {
group.GET("/profile", handleAdminProfile)
// write
group.GET("/write-post", handleAdminPost)
group.GET("/draft-delete", handleDraftDelete)
// manage
group.GET("/manage-posts", handleAdminPosts)
group.GET("/manage-series", handleAdminSeries)