diff --git a/backend/handler/comment.go b/backend/handler/comment.go index fa8383b..ba2fdbc 100644 --- a/backend/handler/comment.go +++ b/backend/handler/comment.go @@ -36,6 +36,21 @@ func (h *Handlers) PostComments(c *gin.Context) { c.JSON(http.StatusNotFound, gin.H{"error": "帖子不存在"}) return } + + if allow, err := h.Setting.AllowComments(); err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": "评论暂时不可用"}) + return + } else if !allow { + c.JSON(http.StatusOK, gin.H{ + "comments": []any{}, + "total": 0, + "total_comments": 0, + "page": page, + "size": size, + }) + return + } + boardID, _ := h.Post.GetBoardID(uint(id)) comments, floors, totalComments, err := h.Comment.ListFloorPaged(uint(id), boardID, viewerID, actor, page, size) @@ -70,7 +85,7 @@ func (h *Handlers) CreateComment(c *gin.Context) { c.JSON(http.StatusInternalServerError, gin.H{"error": "评论暂时不可用"}) return } else if !allow { - c.JSON(http.StatusForbidden, gin.H{"error": "站点已关闭评论"}) + c.JSON(http.StatusForbidden, gin.H{"error": "本站不支持评论"}) return } var req CreateCommentRequest diff --git a/backend/handler/user.go b/backend/handler/user.go index ed232f7..736cb0b 100644 --- a/backend/handler/user.go +++ b/backend/handler/user.go @@ -151,6 +151,21 @@ func (h *Handlers) UserComments(c *gin.Context) { return } + if allow, err := h.Setting.AllowComments(); err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"error": "评论暂时不可用"}) + return + } else if !allow { + page, _ := strconv.Atoi(c.DefaultQuery("page", "1")) + size, _ := strconv.Atoi(c.DefaultQuery("size", "20")) + c.JSON(http.StatusOK, gin.H{ + "comments": []any{}, + "total": 0, + "page": page, + "size": size, + }) + return + } + page, _ := strconv.Atoi(c.DefaultQuery("page", "1")) size, _ := strconv.Atoi(c.DefaultQuery("size", "20")) diff --git a/frontend/app/admin/announcements/AnnouncementAdmin.tsx b/frontend/app/admin/announcements/AnnouncementAdmin.tsx index 2909dbb..9fa380c 100644 --- a/frontend/app/admin/announcements/AnnouncementAdmin.tsx +++ b/frontend/app/admin/announcements/AnnouncementAdmin.tsx @@ -25,6 +25,7 @@ import { toast } from "@/lib/toast"; import ConfirmDialog from "@/components/ConfirmDialog"; import { AdminEmpty, + AdminField, AdminIconButton, AdminPageHeader, AdminSegmented, @@ -155,29 +156,24 @@ export default function AnnouncementAdmin({ {form.id == null ? "新建公告" : "编辑公告"}

- - setForm({ ...form, title: e.target.value })} + onChange={(title) => setForm({ ...form, title })} placeholder="请输入公告标题" />
- - setForm({ ...form, tag: e.target.value })} + onChange={(tag) => setForm({ ...form, tag })} placeholder="公告" />
@@ -213,14 +209,13 @@ export default function AnnouncementAdmin({ />
- -