fix: allow option parsing if only one is present (#60)
This commit is contained in:
parent
7cf3839f41
commit
991b5b46f4
@ -1,6 +1,8 @@
|
|||||||
package middleware
|
package middleware
|
||||||
|
|
||||||
import "github.com/gin-gonic/gin"
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
func OptionsMiddleware() gin.HandlerFunc {
|
func OptionsMiddleware() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
@ -8,23 +10,17 @@ func OptionsMiddleware() gin.HandlerFunc {
|
|||||||
c.Set("theme", "dark")
|
c.Set("theme", "dark")
|
||||||
|
|
||||||
imagesCookie, err := c.Cookie("disable_images")
|
imagesCookie, err := c.Cookie("disable_images")
|
||||||
if err != nil {
|
if err == nil {
|
||||||
c.Next()
|
if imagesCookie == "true" {
|
||||||
return
|
c.Set("disable_images", true)
|
||||||
}
|
}
|
||||||
|
|
||||||
if imagesCookie == "true" {
|
|
||||||
c.Set("disable_images", true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
themeCookie, err := c.Cookie("theme")
|
themeCookie, err := c.Cookie("theme")
|
||||||
if err != nil {
|
if err == nil {
|
||||||
c.Next()
|
if themeCookie == "light" {
|
||||||
return
|
c.Set("theme", "light")
|
||||||
}
|
}
|
||||||
|
|
||||||
if themeCookie == "light" {
|
|
||||||
c.Set("theme", "light")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Next()
|
c.Next()
|
||||||
|
@ -30,12 +30,10 @@ func ChangeOptions(c *gin.Context) {
|
|||||||
if c.MustGet("theme").(string) == "dark" {
|
if c.MustGet("theme").(string) == "dark" {
|
||||||
text = "light"
|
text = "light"
|
||||||
}
|
}
|
||||||
|
|
||||||
c.SetCookie("theme", text, 60*60*24*365*10, "/", "", false, true)
|
c.SetCookie("theme", text, 60*60*24*365*10, "/", "", false, true)
|
||||||
// get redirect url from query
|
// get redirect url from query
|
||||||
redirectUrl := c.Query("redirect_url")
|
redirectUrl := c.Query("redirect_url")
|
||||||
if redirectUrl == "" {
|
|
||||||
redirectUrl = os.Getenv("APP_URL")
|
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.HasPrefix(redirectUrl, os.Getenv("APP_URL")) {
|
if !strings.HasPrefix(redirectUrl, os.Getenv("APP_URL")) {
|
||||||
redirectUrl = os.Getenv("APP_URL")
|
redirectUrl = os.Getenv("APP_URL")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user