From 991b5b46f478b67247d06ffcccce12a4d2ee9596 Mon Sep 17 00:00:00 2001 From: httpjamesm <51917118+httpjamesm@users.noreply.github.com> Date: Sun, 24 Sep 2023 00:59:48 -0400 Subject: [PATCH] fix: allow option parsing if only one is present (#60) --- src/middleware/options.go | 26 +++++++++++--------------- src/routes/options.go | 4 +--- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/middleware/options.go b/src/middleware/options.go index 8a4ca64..95b9d94 100644 --- a/src/middleware/options.go +++ b/src/middleware/options.go @@ -1,6 +1,8 @@ package middleware -import "github.com/gin-gonic/gin" +import ( + "github.com/gin-gonic/gin" +) func OptionsMiddleware() gin.HandlerFunc { return func(c *gin.Context) { @@ -8,23 +10,17 @@ func OptionsMiddleware() gin.HandlerFunc { c.Set("theme", "dark") imagesCookie, err := c.Cookie("disable_images") - if err != nil { - c.Next() - return - } - - if imagesCookie == "true" { - c.Set("disable_images", true) + if err == nil { + if imagesCookie == "true" { + c.Set("disable_images", true) + } } themeCookie, err := c.Cookie("theme") - if err != nil { - c.Next() - return - } - - if themeCookie == "light" { - c.Set("theme", "light") + if err == nil { + if themeCookie == "light" { + c.Set("theme", "light") + } } c.Next() diff --git a/src/routes/options.go b/src/routes/options.go index b1b3293..a665be2 100644 --- a/src/routes/options.go +++ b/src/routes/options.go @@ -30,12 +30,10 @@ func ChangeOptions(c *gin.Context) { if c.MustGet("theme").(string) == "dark" { text = "light" } + c.SetCookie("theme", text, 60*60*24*365*10, "/", "", false, true) // get redirect url from query redirectUrl := c.Query("redirect_url") - if redirectUrl == "" { - redirectUrl = os.Getenv("APP_URL") - } if !strings.HasPrefix(redirectUrl, os.Getenv("APP_URL")) { redirectUrl = os.Getenv("APP_URL")