Make multiple filters actually function, instead of only applying the last filter
This commit is contained in:
parent
9a2bf05790
commit
64e756f6a3
|
@ -5,6 +5,7 @@ Copyright © 2023 Seednode <seednode@seedno.de>
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
)
|
||||
|
@ -41,26 +42,30 @@ 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() {
|
||||
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))
|
||||
result = slices.DeleteFunc(result, func(s string) bool {
|
||||
var delete bool = true
|
||||
|
||||
p := filepath.Base(s)
|
||||
|
||||
for _, include := range filters.included {
|
||||
if (CaseSensitive && strings.Contains(p, include)) || (!CaseSensitive && strings.Contains(strings.ToLower(p), strings.ToLower(include))) {
|
||||
delete = false
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return delete
|
||||
})
|
||||
}
|
||||
|
||||
return result
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
ReleaseVersion string = "0.96.1"
|
||||
ReleaseVersion string = "0.96.2"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue