Skip to content

Commit

Permalink
🎨 废弃评论推送社区接口 Fix #27
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Mar 31, 2020
1 parent bc74737 commit 0e8230e
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 82 deletions.
75 changes: 0 additions & 75 deletions controller/b3logctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,81 +21,6 @@ import (
"github.com/gin-gonic/gin"
)

// addSymCommentAction adds a comment come from Sym. Sees https://hacpai.com/article/1457158841475 for more details.
func addSymCommentAction(c *gin.Context) {
result := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, result)

arg := map[string]interface{}{}
if err := c.BindJSON(&arg); nil != err {
result.Code = util.CodeErr
result.Msg = "parses add comment request failed"

return
}

logger.Infof("Add a comment from Sym: %+v", arg)

client := arg["client"].(map[string]interface{})
b3Key := client["userB3Key"].(string)
articleAuthorName := client["userName"].(string)
articleAuthor := service.User.GetUserByName(articleAuthorName)
if articleAuthor.B3Key != b3Key {
result.Code = util.CodeErr
result.Msg = "wrong B3 Key"

return
}

requestCmt := arg["comment"].(map[string]interface{})
articleId, err := strconv.ParseUint(requestCmt["articleId"].(string), 10, 64)
if nil != err {
result.Code = util.CodeErr
result.Msg = "parses add comment request failed"

return
}

article := service.Article.ConsoleGetArticle(articleId)
if nil == article {
result.Code = util.CodeErr
result.Msg = "not found the specified article"

return
}

blogID := getBlogID(c)
commentableSetting := service.Setting.GetSetting(model.SettingCategoryBasic, model.SettingNameBasicCommentable, blogID)
if "true" != commentableSetting.Value || !article.Commentable {
result.Code = util.CodeErr
result.Msg = "not allow comment"

return
}

comment := &model.Comment{
BlogID: blogID,
ArticleID: articleId,
AuthorID: model.SyncCommentAuthorID,
Content: requestCmt["content"].(string),
IP: "",
UserAgent: "",
AuthorName: requestCmt["authorName"].(string),
AuthorURL: requestCmt["authorURL"].(string),
AuthorAvatarURL: requestCmt["authorAvatarURL"].(string),
}

if err := service.Comment.AddComment(comment); nil != err {
result.Code = util.CodeErr
result.Msg = err.Error()
}

if err := service.Comment.UpdatePushedAt(comment); nil != err {
result.Code = util.CodeErr
result.Msg = err.Error()
}
}

// addSymArticleAction adds an article come from Sym. Sees https://hacpai.com/article/1457158841475 for more details.
func addSymArticleAction(c *gin.Context) {
result := gulu.Ret.NewResult()
Expand Down
4 changes: 0 additions & 4 deletions controller/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,6 @@ func routePath(c *gin.Context) {
case util.PathManifest:
showManifestAction(c)

return
case util.PathAPIsSymComment:
addSymCommentAction(c)

return
case util.PathAPIsSymArticle:
addSymArticleAction(c)
Expand Down
4 changes: 1 addition & 3 deletions util/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,14 @@ const (
PathChangelogs = "/changelogs"
PathRobots = "/robots.txt"
PathAPIsSymArticle = "/apis/symphony/article"
PathAPIsSymComment = "/apis/symphony/comment"
PathPlatInfo = "/blog/info"
PathManifest = "/manifest.json"
)

var reservedPaths = []string{
PathSearch, PathOpensearch, PathBlogs, PathConsoleDist, PathAdmin, PathAPI, PathFavicon, PathTheme,
PathActivities, PathArchives, PathAuthors, PathCategories, PathTags, PathComments, PathAtom, PathRSS,
PathSitemap, PathChangelogs, PathRobots, PathAPIsSymArticle,
PathAPIsSymComment, PathPlatInfo,
PathSitemap, PathChangelogs, PathRobots, PathAPIsSymArticle, PathPlatInfo,
}

// IsReservedPath checks the specified path is a reserved path or not.
Expand Down

0 comments on commit 0e8230e

Please sign in to comment.