commit 230d30524699b80a5e40289343893551413a11ac
parent b5560d8ef9b7a904c19cb40e916dd0239d6fa483
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Sat, 22 Feb 2025 07:51:20 -0800
keep using gzip for top-bar endpoint if user is not using stream version
Diffstat:
2 files changed, 28 insertions(+), 24 deletions(-)
diff --git a/pkg/web/middlewares/middlewares.go b/pkg/web/middlewares/middlewares.go
@@ -22,29 +22,33 @@ import (
)
// GzipMiddleware ...
-var GzipMiddleware = middleware.GzipWithConfig(
- middleware.GzipConfig{
- Level: 5,
- Skipper: func(c echo.Context) bool {
- if c.Path() == "/bhcli/downloads/:filename" ||
- c.Path() == "/vip/downloads/:filename" ||
- c.Path() == "/vip/challenges/re-1/:filename" ||
- c.Path() == "/chess/:key" ||
- c.Path() == "/chess/:key/analyze" ||
- c.Path() == "/poker/:roomID/stream" ||
- c.Path() == "/poker/:roomID/logs" ||
- c.Path() == "/poker/:roomID/bet" ||
- c.Path() == "/api/v1/chat/messages/:roomName/stream" ||
- c.Path() == "/api/v1/chat/messages/:roomName/stream/menu" ||
- c.Path() == "/api/v1/chat/top-bar/:roomName" ||
- c.Path() == "/uploads/:filename" ||
- c.Path() == "/" {
- return true
- }
- return false
- },
- },
-)
+func GzipMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
+ return func(c echo.Context) error {
+ authUser := c.Get("authUser").(*database.User)
+ cfg := middleware.GzipConfig{
+ Level: 5,
+ Skipper: func(c echo.Context) bool {
+ if c.Path() == "/bhcli/downloads/:filename" ||
+ c.Path() == "/vip/downloads/:filename" ||
+ c.Path() == "/vip/challenges/re-1/:filename" ||
+ c.Path() == "/chess/:key" ||
+ c.Path() == "/chess/:key/analyze" ||
+ c.Path() == "/poker/:roomID/stream" ||
+ c.Path() == "/poker/:roomID/logs" ||
+ c.Path() == "/poker/:roomID/bet" ||
+ c.Path() == "/api/v1/chat/messages/:roomName/stream" ||
+ c.Path() == "/api/v1/chat/messages/:roomName/stream/menu" ||
+ (c.Path() == "/api/v1/chat/top-bar/:roomName" && authUser.UseStreamTopBar) ||
+ c.Path() == "/uploads/:filename" ||
+ c.Path() == "/" {
+ return true
+ }
+ return false
+ },
+ }
+ return middleware.GzipWithConfig(cfg)(next)(c)
+ }
+}
// BodyLimit ...
var BodyLimit = middleware.BodyLimitWithConfig(middleware.BodyLimitConfig{
diff --git a/pkg/web/web.go b/pkg/web/web.go
@@ -47,9 +47,9 @@ func getMainServer(db *database.DkfDB, i18nBundle *i18n.Bundle, renderer *tmp.Te
e.Use(middlewares.DdosMiddleware)
e.Use(middlewares.MaintenanceMiddleware)
e.Use(middlewares.SecureMiddleware)
+ e.Use(middlewares.SetUserMiddleware)
e.Use(middlewares.GzipMiddleware)
e.Use(middlewares.CSRFMiddleware())
- e.Use(middlewares.SetUserMiddleware)
e.Use(middlewares.I18nMiddleware(i18nBundle, "en"))
e.Use(middlewares.BodyLimit)
e.Use(middlewares.HellbannedCookieMiddleware)