dkforest

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

commit 8df352c17e393a7475c4885d268ba8407481139e
parent 86ca8493d4e1d719a6045dd74773d8c896b0ddc8
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sun, 11 Jun 2023 15:51:07 -0700

cleanup

Diffstat:
Mpkg/web/handlers/handlers.go | 30+++++++++++++++++-------------
1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -5142,12 +5142,16 @@ func ChessGameHandler(c echo.Context) error { } defer usersStreamsManager.Remove(authUser.ID) + send := func(s string) { + _, _ = c.Response().Write([]byte(s)) + } + c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTMLCharsetUTF8) c.Response().WriteHeader(http.StatusOK) c.Response().Header().Set("Transfer-Encoding", "chunked") c.Response().Header().Set("Connection", "keep-alive") - _, _ = c.Response().Write([]byte(cssReset)) + send(cssReset) authorizedChannels := make([]string, 0) authorizedChannels = append(authorizedChannels, key) @@ -5161,7 +5165,7 @@ func ChessGameHandler(c echo.Context) error { } else { card1 = g.DrawPlayerCard(key, isFlipped, false) } - _, _ = c.Response().Write([]byte(fmt.Sprintf(`<div id="div_0">%s</div>`, card1))) + send(fmt.Sprintf(`<div id="div_0">%s</div>`, card1)) i := 0 Loop: @@ -5173,7 +5177,7 @@ Loop: } if g.Game.Outcome() != chess.NoOutcome { - _, _ = c.Response().Write([]byte(`<meta http-equiv="refresh" content="0" />`)) + send(`<meta http-equiv="refresh" content="0" />`) break } @@ -5196,13 +5200,13 @@ Loop: y2 = 7 - y2 } i++ - _, _ = c.Response().Write([]byte(fmt.Sprintf(`<style>@keyframes move_anim_%d { from { left: calc(%d*12.5%%); top: calc(%d*12.5%%); } to { left: calc(%d*12.5%%); top: calc(%d*12.5%%); } }</style>`, i, x1, y1, x2, y2))) - _, _ = c.Response().Write([]byte(fmt.Sprintf(`<style>#%s { animation-name: move_anim_%d; animation-duration: 400ms; animation-fill-mode: forwards; }</style>`, id, i))) + send(fmt.Sprintf(`<style>@keyframes move_anim_%d { from { left: calc(%d*12.5%%); top: calc(%d*12.5%%); } to { left: calc(%d*12.5%%); top: calc(%d*12.5%%); } }</style>`, i, x1, y1, x2, y2)) + send(fmt.Sprintf(`<style>#%s { animation-name: move_anim_%d; animation-duration: 400ms; animation-fill-mode: forwards; }</style>`, id, i)) } animate(payload.Move.S1(), payload.Move.S2(), payload.IDStr1) if payload.IDStr2 != "" { - _, _ = c.Response().Write([]byte(`<style>#` + payload.IDStr2 + ` { display: none; }</style>`)) + send(`<style>#` + payload.IDStr2 + ` { display: none; }</style>`) } if payload.Move.Promo() != chess.NoPieceType { @@ -5224,7 +5228,7 @@ Loop: case chess.Knight: promoImg = "/public/img/chess/" + cTurn + "N.png" } - _, _ = c.Response().Write([]byte(fmt.Sprintf(`<style>#%s { background-image: url("%s") !important; }</style>`, payload.IDStr1, promoImg))) + send(fmt.Sprintf(`<style>#%s { background-image: url("%s") !important; }</style>`, payload.IDStr1, promoImg)) c.Response().Flush() }(payload, c) } @@ -5240,17 +5244,17 @@ Loop: } // Render last move - _, _ = c.Response().Write([]byte(`<style>.square { background-color: transparent !important; }</style>`)) - _, _ = c.Response().Write([]byte(fmt.Sprintf(`<style>.square_%d, .square_%d { background-color: rgba(0, 255, 0, 0.2) !important; }</style>`, int(payload.Move.S1()), int(payload.Move.S2())))) + send(`<style>.square { background-color: transparent !important; }</style>`) + send(fmt.Sprintf(`<style>.square_%d, .square_%d { background-color: rgba(0, 255, 0, 0.2) !important; }</style>`, int(payload.Move.S1()), int(payload.Move.S2()))) // Reset kings background to transparent - _, _ = c.Response().Write([]byte(`<style>#img_4 { background-color: transparent !important; }</style>`)) - _, _ = c.Response().Write([]byte(`<style>#img_60 { background-color: transparent !important; }</style>`)) + send(`<style>#img_4 { background-color: transparent !important; }</style>`) + send(`<style>#img_60 { background-color: transparent !important; }</style>`) // Render "checks" red background if payload.CheckW { - _, _ = c.Response().Write([]byte(`<style>#img_4 { background-color: rgba(255, 0, 0, 0.4) !important; }</style>`)) + send(`<style>#img_4 { background-color: rgba(255, 0, 0, 0.4) !important; }</style>`) } else if payload.CheckB { - _, _ = c.Response().Write([]byte(`<style>#img_60 { background-color: rgba(255, 0, 0, 0.4) !important; }</style>`)) + send(`<style>#img_60 { background-color: rgba(255, 0, 0, 0.4) !important; }</style>`) } c.Response().Flush()