mirror of
https://github.com/eiblog/eiblog.git
synced 2026-03-01 00:34:58 +08:00
fix: fist comment of disqus error
This commit is contained in:
@@ -301,7 +301,7 @@ func handleAPIPostCreate(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
// 旧文章
|
// 旧文章
|
||||||
article.ID = cid
|
article.ID = cid
|
||||||
artc, _ := cache.Ei.FindArticleByID(article.ID)
|
artc, _ := cache.Ei.FindArticleByID(article.ID) // cache
|
||||||
if artc != nil {
|
if artc != nil {
|
||||||
article.IsDraft = false
|
article.IsDraft = false
|
||||||
article.Count = artc.Count
|
article.Count = artc.Count
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package page
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
htemplate "html/template"
|
htemplate "html/template"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@@ -198,7 +199,8 @@ func handleDisqusList(c *gin.Context) {
|
|||||||
|
|
||||||
slug := c.Param("slug")
|
slug := c.Param("slug")
|
||||||
cursor := c.Query("cursor")
|
cursor := c.Query("cursor")
|
||||||
if artc := cache.Ei.ArticlesMap[slug]; artc != nil {
|
artc := cache.Ei.ArticlesMap[slug]
|
||||||
|
if artc != nil {
|
||||||
dcs.Data.Thread = artc.Thread
|
dcs.Data.Thread = artc.Thread
|
||||||
}
|
}
|
||||||
postsList, err := internal.PostsList(slug, cursor)
|
postsList, err := internal.PostsList(slug, cursor)
|
||||||
@@ -229,6 +231,18 @@ func handleDisqusList(c *gin.Context) {
|
|||||||
IsDeleted: v.IsDeleted,
|
IsDeleted: v.IsDeleted,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// query thread & update
|
||||||
|
if artc != nil && artc.Thread == "" {
|
||||||
|
if dcs.Data.Thread != "" {
|
||||||
|
artc.Thread = dcs.Data.Thread
|
||||||
|
} else if internal.ThreadDetails(artc) == nil {
|
||||||
|
dcs.Data.Thread = artc.Thread
|
||||||
|
}
|
||||||
|
cache.Ei.UpdateArticle(context.Background(), artc.ID,
|
||||||
|
map[string]interface{}{
|
||||||
|
"thread": artc.Thread,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleDisqusPage 评论页
|
// handleDisqusPage 评论页
|
||||||
|
|||||||
@@ -16,11 +16,12 @@ import (
|
|||||||
|
|
||||||
// disqus api
|
// disqus api
|
||||||
const (
|
const (
|
||||||
apiPostsCount = "https://disqus.com/api/3.0/threads/set.json"
|
apiPostsCount = "https://disqus.com/api/3.0/threads/set.json"
|
||||||
apiPostsList = "https://disqus.com/api/3.0/threads/listPosts.json"
|
apiPostsList = "https://disqus.com/api/3.0/threads/listPosts.json"
|
||||||
apiPostCreate = "https://disqus.com/api/3.0/posts/create.json"
|
apiPostCreate = "https://disqus.com/api/3.0/posts/create.json"
|
||||||
apiPostApprove = "https://disqus.com/api/3.0/posts/approve.json"
|
apiPostApprove = "https://disqus.com/api/3.0/posts/approve.json"
|
||||||
apiThreadCreate = "https://disqus.com/api/3.0/threads/create.json"
|
apiThreadCreate = "https://disqus.com/api/3.0/threads/create.json"
|
||||||
|
apiThreadDetails = "https://disqus.com/api/3.0/threads/details.json"
|
||||||
)
|
)
|
||||||
|
|
||||||
func checkDisqusConfig() error {
|
func checkDisqusConfig() error {
|
||||||
@@ -295,3 +296,46 @@ func ThreadCreate(article *model.Article, btitle string) error {
|
|||||||
article.Thread = result.Response.ID
|
article.Thread = result.Response.ID
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// threadDetailsResp thread info
|
||||||
|
type threadDetailsResp struct {
|
||||||
|
Code int
|
||||||
|
Response struct {
|
||||||
|
ID string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ThreadDetails thread详细
|
||||||
|
func ThreadDetails(article *model.Article) error {
|
||||||
|
if err := checkDisqusConfig(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
vals := url.Values{}
|
||||||
|
vals.Set("api_key", config.Conf.EiBlogApp.Disqus.PublicKey)
|
||||||
|
vals.Set("access_token", config.Conf.EiBlogApp.Disqus.AccessToken)
|
||||||
|
vals.Set("forum", config.Conf.EiBlogApp.Disqus.ShortName)
|
||||||
|
vals.Set("thread:ident", "post-"+article.Slug)
|
||||||
|
|
||||||
|
resp, err := httpPost(apiThreadDetails, vals)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
b, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return errors.New(string(b))
|
||||||
|
}
|
||||||
|
|
||||||
|
result := &threadDetailsResp{}
|
||||||
|
err = json.Unmarshal(b, result)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
article.Thread = result.Response.ID
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ type Article struct {
|
|||||||
SerieID int `gorm:"column:serie_id;not null" bson:"serie_id"` // 专题ID
|
SerieID int `gorm:"column:serie_id;not null" bson:"serie_id"` // 专题ID
|
||||||
Tags pq.StringArray `gorm:"column:tags;type:text[]" bson:"tags"` // tags
|
Tags pq.StringArray `gorm:"column:tags;type:text[]" bson:"tags"` // tags
|
||||||
IsDraft bool `gorm:"column:is_draft;not null" bson:"is_draft"` // 是否是草稿
|
IsDraft bool `gorm:"column:is_draft;not null" bson:"is_draft"` // 是否是草稿
|
||||||
|
Thread string `gorm:"column:thread" bson:"thread"` // disqus thread
|
||||||
|
|
||||||
DeletedAt time.Time `gorm:"column:deleted_at;not null" bson:"deleted_at"` // 删除时间
|
DeletedAt time.Time `gorm:"column:deleted_at;not null" bson:"deleted_at"` // 删除时间
|
||||||
UpdatedAt time.Time `gorm:"column:updated_at;default:current_timestamp" bson:"updated_at"` // 更新时间
|
UpdatedAt time.Time `gorm:"column:updated_at;default:current_timestamp" bson:"updated_at"` // 更新时间
|
||||||
@@ -28,7 +29,6 @@ type Article struct {
|
|||||||
Header string `gorm:"-" bson:"-"` // header
|
Header string `gorm:"-" bson:"-"` // header
|
||||||
Excerpt string `gorm:"-" bson:"-"` // 预览信息
|
Excerpt string `gorm:"-" bson:"-"` // 预览信息
|
||||||
Desc string `gorm:"-" bson:"-"` // 描述
|
Desc string `gorm:"-" bson:"-"` // 描述
|
||||||
Thread string `gorm:"-" bson:"-"` // disqus thread
|
|
||||||
Prev *Article `gorm:"-" bson:"-"` // 上篇文章
|
Prev *Article `gorm:"-" bson:"-"` // 上篇文章
|
||||||
Next *Article `gorm:"-" bson:"-"` // 下篇文章
|
Next *Article `gorm:"-" bson:"-"` // 下篇文章
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user