42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
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()
|
|
}
|
|
}
|