评论实时更新:SSE 订阅文章频道,发评/编辑/删除/审核通过即时刷新打开中的页面
- internal/hub:按文章 ID 的进程内发布/订阅,信号不携带内容(未审核评论不外泄) - GET /api/comments/stream?post_id=N:SSE 长连 + 25s 心跳 + X-Accel-Buffering off - 广播点:发评论、作者编辑/删除、后台审核通过、后台删除(与公开端共享同一 hub) - 前端 EventSource 静默刷新(不亮加载态、不干扰正在输入/编辑的状态) - requestLog 的 statusRecorder 补 Flush 透传——包装器没实现 Flusher 时流式端点整体不可用
This commit is contained in:
@@ -285,6 +285,7 @@ func (a *API) createComment(w http.ResponseWriter, r *http.Request) {
|
||||
httpx.ServerError(w, err)
|
||||
return
|
||||
}
|
||||
a.Hub.Broadcast(in.PostID)
|
||||
if rateKey != "" {
|
||||
a.commentNew.Add(rateKey) // 只计成功写入:空正文这类手滑不扣配额
|
||||
}
|
||||
@@ -390,6 +391,7 @@ func (a *API) editComment(w http.ResponseWriter, r *http.Request, id int64) {
|
||||
httpx.ServerError(w, err)
|
||||
return
|
||||
}
|
||||
a.Hub.Broadcast(updated.PostID)
|
||||
httpx.OK(w, updated)
|
||||
}
|
||||
|
||||
@@ -417,6 +419,7 @@ func (a *API) deleteComment(w http.ResponseWriter, r *http.Request, id int64) {
|
||||
httpx.ServerError(w, err)
|
||||
return
|
||||
}
|
||||
a.Hub.Broadcast(c.PostID)
|
||||
httpx.OK(w, map[string]any{"ok": true})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user