弹幕:广播带半显用户名(前两字+***),前端展示前缀
Made-with: Cursor
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user