From 01335ea06c7fe126f73eca1591ae2df82ebfb1d1 Mon Sep 17 00:00:00 2001
From: deepzz0
Date: Thu, 8 Dec 2016 23:15:40 +0800
Subject: [PATCH] fix article list error
---
api.go | 24 +++++++++---------------
back.go | 4 ++--
conf/app.yml | 2 +-
db.go | 13 ++++++++++++-
views/admin/profile.html | 2 +-
5 files changed, 25 insertions(+), 20 deletions(-)
diff --git a/api.go b/api.go
index 8746fb8..28a54bc 100644
--- a/api.go
+++ b/api.go
@@ -194,14 +194,13 @@ func apiPostAdd(c *gin.Context) {
if tag != "" {
tags = strings.Split(tag, ",")
}
- t := CheckDate(date)
serieid := CheckSerieID(serie)
publish = CheckPublish(do)
artc := &Article{
Title: title,
Content: text,
Slug: slug,
- CreateTime: t,
+ CreateTime: CheckDate(date),
IsDraft: !publish,
Author: Ei.Username,
SerieID: serieid,
@@ -222,16 +221,20 @@ func apiPostAdd(c *gin.Context) {
return
}
artc.ID = int32(cid)
- if CheckBool(c.PostForm("update")) {
- artc.UpdateTime = time.Now()
- }
i, a := GetArticle(artc.ID)
if a != nil {
artc.IsDraft = false
artc.Count = a.Count
artc.UpdateTime = a.UpdateTime
+ Ei.Articles = append(Ei.Articles[0:i], Ei.Articles[i+1:]...)
+ DelFromLinkedList(a)
+ ManageTagsArticle(a, false, DELETE)
+ ManageSeriesArticle(a, false, DELETE)
+ ManageArchivesArticle(a, false, DELETE)
+ delete(Ei.MapArticles, a.Slug)
+ a = nil
}
- if update != "" {
+ if CheckBool(update) {
artc.UpdateTime = time.Now()
}
err = UpdateArticle(bson.M{"id": artc.ID}, artc)
@@ -240,15 +243,6 @@ func apiPostAdd(c *gin.Context) {
return
}
if !artc.IsDraft {
- if a != nil {
- Ei.Articles = append(Ei.Articles[0:i], Ei.Articles[i+1:]...)
- DelFromLinkedList(a)
- ManageTagsArticle(a, false, DELETE)
- ManageSeriesArticle(a, false, DELETE)
- ManageArchivesArticle(a, false, DELETE)
- delete(Ei.MapArticles, a.Slug)
- a = nil
- }
Ei.MapArticles[artc.Slug] = artc
Ei.Articles = append(Ei.Articles, artc)
sort.Sort(Ei.Articles)
diff --git a/back.go b/back.go
index 48679a2..4917842 100644
--- a/back.go
+++ b/back.go
@@ -61,7 +61,7 @@ func HandleLoginPost(c *gin.Context) {
return
}
if Ei.Username != user || !VerifyPasswd(Ei.Password, user, pwd) {
- logd.Print("账号或密码错误", user, pwd)
+ logd.Printf("账号或密码错误 %s, %s", user, pwd)
c.Redirect(http.StatusFound, "/admin/login")
return
}
@@ -105,7 +105,7 @@ func HandlePost(c *gin.Context) {
h["Edit"] = artc
}
}
- if h["Title"] == "" {
+ if h["Title"] == nil {
h["Title"] = "撰写文章 | " + Ei.BTitle
}
h["Path"] = c.Request.URL.Path
diff --git a/conf/app.yml b/conf/app.yml
index 7fd598c..ccea14b 100644
--- a/conf/app.yml
+++ b/conf/app.yml
@@ -3,7 +3,7 @@ runmode: prod
# 回收箱保留48小时
trash: -48
# 定时清理回收箱,%d小时
-clean: 12
+clean: 1
# 首页展示文章数量
pagenum: 10
# 管理界面
diff --git a/db.go b/db.go
index 111fa40..efcc1a1 100644
--- a/db.go
+++ b/db.go
@@ -73,7 +73,17 @@ func init() {
ms.Close()
ms, c = db.Connect(DB, COLLECTION_ARTICLE)
index = mgo.Index{
- Key: []string{"id", "slug"},
+ Key: []string{"id"},
+ Unique: true,
+ DropDups: true,
+ Background: true,
+ Sparse: true,
+ }
+ if err := c.EnsureIndex(index); err != nil {
+ logd.Fatal(err)
+ }
+ index = mgo.Index{
+ Key: []string{"slug"},
Unique: true,
DropDups: true,
Background: true,
@@ -461,6 +471,7 @@ func AddToLinkedList(id int32) {
artc.Prev = Ei.Articles[i-1]
if Ei.Articles[i-1].Next != nil {
artc.Next = Ei.Articles[i-1].Next
+ Ei.Articles[i-1].Next.Prev = artc
}
Ei.Articles[i-1].Next = artc
}
diff --git a/views/admin/profile.html b/views/admin/profile.html
index 57f8b56..39d0133 100644
--- a/views/admin/profile.html
+++ b/views/admin/profile.html
@@ -23,7 +23,7 @@
个人邮箱
- 用于发送告警邮件及其它通知, 建议填写, 如: example#163.com.
+ 用于发送告警邮件及其它通知, 建议填写, 如: example@163.com.