弹幕:广播带半显用户名(前两字+***),前端展示前缀

Made-with: Cursor
This commit is contained in:
whm
2026-03-26 15:04:32 +08:00
parent 2e675bda51
commit 07ae6c02ef
3 changed files with 32 additions and 6 deletions

View File

@@ -28,9 +28,14 @@ func writeDanmakuJSON(ws *websocket.Conn, v any) error {
return ws.WriteMessage(websocket.TextMessage, b)
}
// handleDanmakuWS 弹幕:收 JSON {"text":"..."};未带有效 token 仅可收广播不可发。广播 {"type":"dm","text","ts"},不落库
// handleDanmakuWS 弹幕:收 JSON {"text":"..."};未带有效 token 仅可收广播不可发。广播 {"type":"dm","text","from","ts"},不落库
func handleDanmakuWS(c *gin.Context) {
canSend := handlers.SiteDanmakuTokenValid(c.Query("token"))
claims, tokenOK := handlers.ParseSiteClaims(c.Query("token"))
canSend := tokenOK
fromDisplay := "***"
if tokenOK && claims != nil {
fromDisplay = handlers.MaskSiteUsernameForDanmaku(claims.Username)
}
ws, err := upgrader.Upgrade(c.Writer, c.Request, nil)
if err != nil {
@@ -72,6 +77,7 @@ func handleDanmakuWS(c *gin.Context) {
out, err := json.Marshal(map[string]interface{}{
"type": "dm",
"text": text,
"from": fromDisplay,
"ts": time.Now().UnixMilli(),
})
if err != nil {