dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit 46abe082db8256cab353f918217fa75a234e4401
parent e2d65ab24f5acdbd5fb2c5107d38ced5d0cf9fdb
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Thu, 28 Dec 2023 22:04:11 -0500

cleanup

Diffstat:
Mpkg/web/handlers/api/v1/chat.go | 9++-------
Mpkg/web/handlers/chess.go | 8++------
Mpkg/web/handlers/poker.go | 9+++------
Mpkg/web/handlers/utils/utils.go | 5+++++
4 files changed, 12 insertions(+), 19 deletions(-)

diff --git a/pkg/web/handlers/api/v1/chat.go b/pkg/web/handlers/api/v1/chat.go @@ -109,10 +109,7 @@ func ChatStreamMessagesHandler(c echo.Context) error { return c.Redirect(http.StatusFound, "/") } - // Setup headers for http request - hutils.SetStreamingHeaders(c) - - quit := hutils.CloseSignalChan(c) + quit := hutils.SetStreaming(c) // Keep track of users streams, so we can limit how many are open at one time per user if err := usersStreamsManager.Inst.Add(authUser.ID, ""); err != nil { @@ -433,9 +430,7 @@ func ChatStreamMenuHandler(c echo.Context) error { return c.HTML(http.StatusOK, s) } - // Setup headers for http request - hutils.SetStreamingHeaders(c) - quit := hutils.CloseSignalChan(c) + quit := hutils.SetStreaming(c) send := func(s string) { _, _ = c.Response().Write([]byte(s)) } selfRefreshLoadingIconTopic := "refresh_loading_icon_" + string(authUser.Username) var prevHash string diff --git a/pkg/web/handlers/chess.go b/pkg/web/handlers/chess.go @@ -118,15 +118,13 @@ func ChessGameAnalyzeHandler(c echo.Context) error { }() } - quit := hutils.CloseSignalChan(c) + quit := hutils.SetStreaming(c) if err := usersStreamsManager.Inst.Add(authUser.ID, "analyze_"+key); err != nil { return nil } defer usersStreamsManager.Inst.Remove(authUser.ID, "analyze_"+key) - hutils.SetStreamingHeaders(c) - sub := interceptors.ChessAnalyzeProgressPubSub.Subscribe([]string{"chess_analyze_progress_" + key}) defer sub.Close() @@ -600,15 +598,13 @@ func ChessGameHandler(c echo.Context) error { // Keep track of "if the game was over" when we loaded the page gameLoadedOver := game.Outcome() != chess.NoOutcome - quit := hutils.CloseSignalChan(c) + quit := hutils.SetStreaming(c) if err := usersStreamsManager.Inst.Add(authUser.ID, key); err != nil { return nil } defer usersStreamsManager.Inst.Remove(authUser.ID, key) - hutils.SetStreamingHeaders(c) - send(hutils.HtmlCssReset) send(`<style>html, body { background-color: #222; }</style>`) diff --git a/pkg/web/handlers/poker.go b/pkg/web/handlers/poker.go @@ -417,8 +417,7 @@ func PokerStreamHandler(c echo.Context) error { g := poker.PokerInstance.GetOrCreateGame(db, roomID, pokerTable.ID, pokerTable.MinBet, pokerTable.IsTest) - quit := hutils.CloseSignalChan(c) - hutils.SetStreamingHeaders(c) + quit := hutils.SetStreaming(c) // Keep track of users streams, so we can limit how many are open at one time per user if err := usersStreamsManager.Inst.Add(authUser.ID, roomTopic); err != nil { @@ -452,8 +451,7 @@ func PokerLogsHandler(c echo.Context) error { roomLogsTopic := roomID.LogsTopic() sub := poker.PubSub.Subscribe([]string{roomLogsTopic}) defer sub.Close() - quit := hutils.CloseSignalChan(c) - hutils.SetStreamingHeaders(c) + quit := hutils.SetStreaming(c) // Keep track of users streams, so we can limit how many are open at one time per user if err := usersStreamsManager.Inst.Add(authUser.ID, roomLogsTopic); err != nil { @@ -492,8 +490,7 @@ func PokerBetHandler(c echo.Context) error { roomUserTopic := roomID.UserTopic(authUser.ID) sub := poker.PubSub.Subscribe([]string{roomID.Topic(), roomUserTopic}) defer sub.Close() - quit := hutils.CloseSignalChan(c) - hutils.SetStreamingHeaders(c) + quit := hutils.SetStreaming(c) // Keep track of users streams, so we can limit how many are open at one time per user if err := usersStreamsManager.Inst.Add(authUser.ID, roomUserTopic); err != nil { diff --git a/pkg/web/handlers/utils/utils.go b/pkg/web/handlers/utils/utils.go @@ -222,6 +222,11 @@ func CloseSignalChan(c echo.Context) <-chan struct{} { return ctx.Done() } +func SetStreaming(c echo.Context) <-chan struct{} { + SetStreamingHeaders(c) + return CloseSignalChan(c) +} + func GetReferer(c echo.Context) string { return c.Request().Referer() }