dkforest

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

commit 316465843e7b4720d39668708a14f6e514fda04b
parent 5ac945592e233ce0529e6cd0885b2a04330ed831
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Mon, 11 Dec 2023 15:19:02 -0500

cleanup

Diffstat:
Mpkg/web/handlers/chess.go | 52+++-------------------------------------------------
Mpkg/web/handlers/poker/poker.go | 64+++++++++-------------------------------------------------------
Mpkg/web/handlers/utils/utils.go | 46++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 58 insertions(+), 104 deletions(-)

diff --git a/pkg/web/handlers/chess.go b/pkg/web/handlers/chess.go @@ -48,52 +48,6 @@ const ( staleMateGame = "d4 d5 Nf3 Nf6 Bf4 Bg4 e3 e6 Bd3 c6 c3 Bd6 Bg3 Bxg3 hxg3 Nbd7 Nbd2 Ne4 Bxe4 dxe4 Nxe4 f5 Ned2 Qf6 Qa4 Nb6 Qb4 Qe7 Qxe7+ Kxe7 Ne5 Nd7 f3 Bh5 Rxh5 Nxe5 dxe5 g6 Rd1 Rad8 Nc4 Rxd1+ Kxd1 gxh5 Nd6 Rg8 Nxb7 Rxg3 Nc5 Rxg2 Kc1 Re2 e4 fxe4 Nxe4 h4 Ng5 h6 Nh3 Rh2 Nf4 h3 a4 Rh1+ Kc2 h2 Nh3 Rf1 f4 h1=Q f5 Qxh3 Kb3 Qxf5 a5 Qxe5 a6 Ra1 c4 Qe3+ Kb4 h5 b3 h4 c5 h3 Kc4 h2 Kb4" ) -var cssReset = `<style> - html, body, div, span, applet, object, iframe, - h1, h2, h3, h4, h5, h6, p, blockquote, pre, - a, abbr, acronym, address, big, cite, code, - del, dfn, em, img, ins, kbd, q, s, samp, - small, strike, strong, sub, sup, tt, var, - b, u, i, center, - dl, dt, dd, ol, ul, li, - fieldset, form, label, legend, - table, caption, tbody, tfoot, thead, tr, th, td, - article, aside, canvas, details, embed, - figure, figcaption, footer, header, hgroup, - menu, nav, output, ruby, section, summary, - time, mark, audio, video { - margin: 0; - padding: 0; - border: 0; - font-size: 100%; - font: inherit; - vertical-align: baseline; - } - - article, aside, details, figcaption, figure, - footer, header, hgroup, menu, nav, section { - display: block; - } - body { - line-height: 1; - } - ol, ul { - list-style: none; - } - blockquote, q { - quotes: none; - } - blockquote:before, blockquote:after, - q:before, q:after { - content: ''; - content: none; - } - table { - border-collapse: collapse; - border-spacing: 0; - } -</style>` - func ChessHandler(c echo.Context) error { authUser := c.Get("authUser").(*database.User) db := c.Get("database").(*database.DkfDB) @@ -227,7 +181,7 @@ func ChessGameStatsHandler(c echo.Context) error { if err != nil { return c.NoContent(http.StatusOK) } - htmlTmpl := cssReset + ` + htmlTmpl := hutils.HtmlCssReset + ` <style> .graph { border: 0px solid #000; @@ -504,7 +458,7 @@ button { return hutils.RedirectReferer(c) } - htmlTmpl := cssReset + interceptors.ChessCSS + ` + htmlTmpl := hutils.HtmlCssReset + interceptors.ChessCSS + ` <form method="post"> <input type="hidden" name="csrf" value="{{ .CSRF }}" /> <input type="hidden" name="move_idx" value="{{ .MoveIdx }}" /> @@ -655,7 +609,7 @@ func ChessGameHandler(c echo.Context) error { hutils.SetStreamingHeaders(c) - send(cssReset) + send(hutils.HtmlCssReset) send(`<style>html, body { background-color: #222; }</style>`) authorizedChannels := make([]string, 0) diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go @@ -1015,7 +1015,7 @@ func PokerCheckHandler(c echo.Context) error { default: } } - return c.HTML(http.StatusOK, cssReset+`<form method="post"><button>Check</button></form>`) + return c.HTML(http.StatusOK, hutils.HtmlCssReset+`<form method="post"><button>Check</button></form>`) } func PokerBetHandler(c echo.Context) error { @@ -1048,7 +1048,7 @@ func PokerBetHandler(c echo.Context) error { } } } - html := cssReset + ` + html := hutils.HtmlCssReset + ` <form method="post"> <input type="number" name="betValue" value="` + itoa(bet) + `" style="width: 90px;" /><button type="submit" name="bet" value="bet">Bet</button><br /> <button type="submit" name="bet" value="bet50">50</button> @@ -1072,7 +1072,7 @@ func PokerCallHandler(c echo.Context) error { default: } } - return c.HTML(http.StatusOK, cssReset+`<form method="post"><button>Call</button></form>`) + return c.HTML(http.StatusOK, hutils.HtmlCssReset+`<form method="post"><button>Call</button></form>`) } func PokerFoldHandler(c echo.Context) error { @@ -1088,7 +1088,7 @@ func PokerFoldHandler(c echo.Context) error { default: } } - return c.HTML(http.StatusOK, cssReset+`<form method="post"><button>Fold</button></form>`) + return c.HTML(http.StatusOK, hutils.HtmlCssReset+`<form method="post"><button>Fold</button></form>`) } func PokerDealHandler(c echo.Context) error { @@ -1102,7 +1102,7 @@ func PokerDealHandler(c echo.Context) error { if c.Request().Method == http.MethodPost { g.Deal(db, roomID, authUser) } - html := cssReset + html := hutils.HtmlCssReset html += `<form method="post"><button>Deal</button></form>` return c.HTML(http.StatusOK, html) } @@ -1123,14 +1123,14 @@ func PokerUnSitHandler(c echo.Context) error { newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s un-sit", authUser.Username.String())) } } - html := cssReset + html := hutils.HtmlCssReset html += `<form method="post"><button>UnSit</button></form>` return c.HTML(http.StatusOK, html) } func PokerSitHandler(c echo.Context) error { db := c.Get("database").(*database.DkfDB) - html := cssReset + `<form method="post"><button>Sit</button></form>` + html := hutils.HtmlCssReset + `<form method="post"><button>Sit</button></form>` authUser := c.Get("authUser").(*database.User) pos, _ := strconv.Atoi(c.Param("pos")) if pos < 1 || pos > NbPlayers { @@ -1248,7 +1248,7 @@ func buildPayloadHtml(g *PokerGame, authUser *database.User, payload any) (html } func buildBaseHtml(g *PokerGame, authUser *database.User, roomID string) (html string) { - html += cssReset + html += hutils.HtmlCssReset html += pokerCss //html += `<script>document.onclick = function(e) { console.log(e.x, e.y); };</script>` // TODO: dev only html += `<div id="table"></div>` @@ -1572,52 +1572,6 @@ func itoa(i int) string { return strconv.Itoa(i) } -var cssReset = `<style> - html, body, div, span, applet, object, iframe, - h1, h2, h3, h4, h5, h6, p, blockquote, pre, - a, abbr, acronym, address, big, cite, code, - del, dfn, em, img, ins, kbd, q, s, samp, - small, strike, strong, sub, sup, tt, var, - b, u, i, center, - dl, dt, dd, ol, ul, li, - fieldset, form, label, legend, - table, caption, tbody, tfoot, thead, tr, th, td, - article, aside, canvas, details, embed, - figure, figcaption, footer, header, hgroup, - menu, nav, output, ruby, section, summary, - time, mark, audio, video { - margin: 0; - padding: 0; - border: 0; - font-size: 100%; - font: inherit; - vertical-align: baseline; - } - - article, aside, details, figcaption, figure, - footer, header, hgroup, menu, nav, section { - display: block; - } - body { - line-height: 1; - } - ol, ul { - list-style: none; - } - blockquote, q { - quotes: none; - } - blockquote:before, blockquote:after, - q:before, q:after { - content: ''; - content: none; - } - table { - border-collapse: collapse; - border-spacing: 0; - } -</style>` - var pokerCss = `<style> html, body { height: 100%; width: 100%; } body { @@ -1838,7 +1792,7 @@ func PokerLogsHandler(c echo.Context) error { quit := hutils.CloseSignalChan(c) hutils.SetStreamingHeaders(c) - send(cssReset) + send(hutils.HtmlCssReset) send(`<style>body { background-color: #ccc; }</style><div style="display:flex;flex-direction:column-reverse;">`) if g.Ongoing != nil { g.Ongoing.LogEventsMtx.RLock() diff --git a/pkg/web/handlers/utils/utils.go b/pkg/web/handlers/utils/utils.go @@ -220,3 +220,49 @@ func GetReferer(c echo.Context) string { func RedirectReferer(c echo.Context) error { return c.Redirect(http.StatusFound, GetReferer(c)) } + +const CssReset = `html, body, div, span, applet, object, iframe, +h1, h2, h3, h4, h5, h6, p, blockquote, pre, +a, abbr, acronym, address, big, cite, code, +del, dfn, em, img, ins, kbd, q, s, samp, +small, strike, strong, sub, sup, tt, var, +b, u, i, center, +dl, dt, dd, ol, ul, li, +fieldset, form, label, legend, +table, caption, tbody, tfoot, thead, tr, th, td, +article, aside, canvas, details, embed, +figure, figcaption, footer, header, hgroup, +menu, nav, output, ruby, section, summary, +time, mark, audio, video { + margin: 0; + padding: 0; + border: 0; + font-size: 100%; + font: inherit; + vertical-align: baseline; +} + +article, aside, details, figcaption, figure, +footer, header, hgroup, menu, nav, section { + display: block; +} +body { + line-height: 1; +} +ol, ul { + list-style: none; +} +blockquote, q { + quotes: none; +} +blockquote:before, blockquote:after, +q:before, q:after { + content: ''; + content: none; +} +table { + border-collapse: collapse; + border-spacing: 0; +}` + +const HtmlCssReset = `<style>` + CssReset + `</html>`