2022-12-27 23:53:28 -05:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import "github.com/gin-gonic/gin"
|
|
|
|
|
|
|
|
func OptionsMiddleware() gin.HandlerFunc {
|
|
|
|
return func(c *gin.Context) {
|
|
|
|
c.Set("disable_images", false)
|
2022-12-28 11:49:14 -05:00
|
|
|
c.Set("theme", "dark")
|
2022-12-27 23:53:28 -05:00
|
|
|
|
2022-12-28 11:49:14 -05:00
|
|
|
imagesCookie, err := c.Cookie("disable_images")
|
2022-12-27 23:53:28 -05:00
|
|
|
if err != nil {
|
|
|
|
c.Next()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-12-28 11:49:14 -05:00
|
|
|
if imagesCookie == "true" {
|
2022-12-27 23:53:28 -05:00
|
|
|
c.Set("disable_images", true)
|
|
|
|
}
|
|
|
|
|
2022-12-28 11:49:14 -05:00
|
|
|
themeCookie, err := c.Cookie("theme")
|
|
|
|
if err != nil {
|
|
|
|
c.Next()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if themeCookie == "light" {
|
|
|
|
c.Set("theme", "light")
|
|
|
|
}
|
|
|
|
|
2022-12-27 23:53:28 -05:00
|
|
|
c.Next()
|
|
|
|
}
|
|
|
|
}
|