整理router
This commit is contained in:
@@ -235,3 +235,9 @@ func ChangePassword(c *gin.Context) {
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"message": "密码修改成功"})
|
||||
}
|
||||
|
||||
// 判断是否为管理员
|
||||
func isAdmin(c *gin.Context) bool {
|
||||
role, exists := c.Get("role")
|
||||
return exists && role == "admin"
|
||||
}
|
||||
|
||||
@@ -17,15 +17,15 @@ func GetComments(c *gin.Context) {
|
||||
postSlug := c.Query("post_slug") // 前台使用 slug
|
||||
status := c.Query("status")
|
||||
pageStr := c.DefaultQuery("page", "1")
|
||||
pageSizeStr := c.DefaultQuery("page_size", "10")
|
||||
pageSizeStr := c.DefaultQuery("page_size", "1000")
|
||||
|
||||
// 解析分页参数
|
||||
page := 1
|
||||
pageSize := 10
|
||||
pageSize := 1000
|
||||
if p, err := strconv.Atoi(pageStr); err == nil && p > 0 {
|
||||
page = p
|
||||
}
|
||||
if ps, err := strconv.Atoi(pageSizeStr); err == nil && ps > 0 && ps <= 100 {
|
||||
if ps, err := strconv.Atoi(pageSizeStr); err == nil && ps > 0 && ps <= 1000 {
|
||||
pageSize = ps
|
||||
}
|
||||
|
||||
|
||||
@@ -371,9 +371,3 @@ func DeletePost(c *gin.Context) {
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{"message": "删除成功"})
|
||||
}
|
||||
|
||||
// 判断是否为管理员
|
||||
func isAdmin(c *gin.Context) bool {
|
||||
role, exists := c.Get("role")
|
||||
return exists && role == "admin"
|
||||
}
|
||||
|
||||
@@ -129,6 +129,15 @@ func IndexView(c *gin.Context) {
|
||||
db.Order("is_top DESC, published_at DESC, created_at DESC").
|
||||
Offset(offset).Limit(pageSize).Find(&posts)
|
||||
|
||||
// 如果摘要为空,则从内容中提取摘要
|
||||
for i := range posts {
|
||||
if posts[i].Summary == "" && posts[i].Content != "" && len(posts[i].Content) > 120 {
|
||||
posts[i].Summary = posts[i].Content[:120]
|
||||
} else {
|
||||
posts[i].Summary = posts[i].Content
|
||||
}
|
||||
}
|
||||
|
||||
totalPages := int(math.Ceil(float64(total) / float64(pageSize)))
|
||||
categories, tags, postCount, categoryCount, tagCount := loadSidebarData()
|
||||
siteName, siteDesc := loadSiteInfo(cfg)
|
||||
@@ -397,7 +406,6 @@ func SubmitComment(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 检查文章是否存在
|
||||
// 检查文章是否存在
|
||||
var post models.Post
|
||||
if err := database.DB.First(&post, req.PostID).Error; err != nil {
|
||||
|
||||
Reference in New Issue
Block a user