Make multiple filters actually function, instead of only applying the last filter

This commit is contained in:
Seednode 2023-09-26 16:37:28 -05:00
parent 9a2bf05790
commit 64e756f6a3
3 changed files with 23 additions and 12 deletions

View File

@ -5,6 +5,7 @@ Copyright © 2023 Seednode <seednode@seedno.de>
package cmd
import (
"path/filepath"
"slices"
"strings"
)
@ -41,27 +42,31 @@ func (filters *filters) apply(fileList []string) []string {
if filters.hasExcludes() {
for _, exclude := range filters.excluded {
result = slices.DeleteFunc(fileList, func(s string) bool {
result = slices.DeleteFunc(result, func(s string) bool {
if CaseSensitive {
return strings.Contains(s, exclude)
return strings.Contains(s, filepath.Base(exclude))
} else {
return strings.Contains(strings.ToLower(s), strings.ToLower(exclude))
return strings.Contains(strings.ToLower(s), strings.ToLower(filepath.Base(exclude)))
}
})
}
}
if filters.hasIncludes() {
result = slices.DeleteFunc(result, func(s string) bool {
var delete bool = true
p := filepath.Base(s)
for _, include := range filters.included {
result = slices.DeleteFunc(fileList, func(s string) bool {
if CaseSensitive {
return !strings.Contains(s, include)
} else {
return !strings.Contains(strings.ToLower(s), strings.ToLower(include))
if (CaseSensitive && strings.Contains(p, include)) || (!CaseSensitive && strings.Contains(strings.ToLower(p), strings.ToLower(include))) {
delete = false
}
}
return delete
})
}
}
return result
}

View File

@ -12,7 +12,7 @@ import (
)
const (
ReleaseVersion string = "0.96.1"
ReleaseVersion string = "0.96.2"
)
var (

View File

@ -165,11 +165,17 @@ func serveRoot(paths []string, regexes *regexes, cache *fileCache, formats *type
strippedRefererUri := strings.TrimPrefix(refererUri, Prefix+mediaPrefix)
fmt.Printf("Includes:\n%v\n", r.URL.Query().Get("include"))
fmt.Printf("Excludes:\n%v\n", r.URL.Query().Get("exclude"))
filters := &filters{
included: splitQueryParams(r.URL.Query().Get("include"), regexes),
excluded: splitQueryParams(r.URL.Query().Get("exclude"), regexes),
}
fmt.Printf("Includes:\n%v\n", filters.included)
fmt.Printf("Excludes:\n%v\n", filters.excluded)
sortOrder := sortOrder(r)
_, refreshInterval := refreshInterval(r)