feat: Add new logic for judge path with *
Some checks failed
build / build (push) Failing after 1m38s

This commit is contained in:
d3m0k1d
2026-01-21 16:07:31 +03:00
parent 16a174cf56
commit b6e92a2a57
2 changed files with 20 additions and 4 deletions

View File

@@ -2,12 +2,12 @@ package judge
import (
"fmt"
"time"
"github.com/d3m0k1d/BanForge/internal/blocker"
"github.com/d3m0k1d/BanForge/internal/config"
"github.com/d3m0k1d/BanForge/internal/logger"
"github.com/d3m0k1d/BanForge/internal/storage"
"strings"
"time"
)
type Judge struct {
@@ -71,7 +71,7 @@ func (j *Judge) ProcessUnviewed() error {
for _, rule := range rules {
if (rule.Method == "" || entry.Method == rule.Method) &&
(rule.Status == "" || entry.Status == rule.Status) &&
(rule.Path == "" || entry.Path == rule.Path) {
matchPath(entry.Path, rule.Path) {
j.logger.Info(
fmt.Sprintf(
@@ -141,3 +141,18 @@ func (j *Judge) UnbanChecker() {
}
}
}
func matchPath(path string, rulePath string) bool {
if rulePath == "" {
return true
}
if strings.HasPrefix(rulePath, "/*") {
prefix := strings.TrimPrefix(rulePath, "*")
return strings.HasPrefix(path, prefix)
}
if strings.HasSuffix(rulePath, "*") {
suffix := strings.TrimSuffix(rulePath, "*")
return strings.HasSuffix(path, suffix)
}
return path == rulePath
}