feat(app state): settings are now global and get updated on the fly
This commit is contained in:
41
backend/internal/router/middleware/settings_Check.go
Normal file
41
backend/internal/router/middleware/settings_Check.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"lst.net/internal/system/settings"
|
||||
)
|
||||
|
||||
func SettingCheckMiddleware(settingName string) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
// Debug: Log the setting name we're checking
|
||||
//log.Printf("Checking setting '%s' for path: %s", settingName, c.Request.URL.Path)
|
||||
|
||||
// Get the current setting value
|
||||
value, err := settings.GetString(settingName)
|
||||
if err != nil {
|
||||
//log.Printf("Error getting setting '%s': %v", settingName, err)
|
||||
c.AbortWithStatusJSON(404, gin.H{
|
||||
"error": "endpoint not available",
|
||||
"details": "setting error",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Debug: Log the actual value received
|
||||
//log.Printf("Setting '%s' value: '%s'", settingName, value)
|
||||
|
||||
// Changed condition to check for "1" (enable) instead of "0" (disable)
|
||||
if value != "1" {
|
||||
//log.Printf("Setting '%s' not enabled (value: '%s')", settingName, value)
|
||||
c.AbortWithStatusJSON(404, gin.H{
|
||||
"error": "endpoint not available",
|
||||
"details": "required feature is disabled",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Debug: Log successful check
|
||||
//log.Printf("Setting check passed for '%s'", settingName)
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user