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
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"path/filepath"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
@ -41,26 +42,30 @@ func (filters *filters) apply(fileList []string) []string {
|
||||||
|
|
||||||
if filters.hasExcludes() {
|
if filters.hasExcludes() {
|
||||||
for _, exclude := range filters.excluded {
|
for _, exclude := range filters.excluded {
|
||||||
result = slices.DeleteFunc(fileList, func(s string) bool {
|
result = slices.DeleteFunc(result, func(s string) bool {
|
||||||
if CaseSensitive {
|
if CaseSensitive {
|
||||||
return strings.Contains(s, exclude)
|
return strings.Contains(s, filepath.Base(exclude))
|
||||||
} else {
|
} else {
|
||||||
return strings.Contains(strings.ToLower(s), strings.ToLower(exclude))
|
return strings.Contains(strings.ToLower(s), strings.ToLower(filepath.Base(exclude)))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if filters.hasIncludes() {
|
if filters.hasIncludes() {
|
||||||
for _, include := range filters.included {
|
result = slices.DeleteFunc(result, func(s string) bool {
|
||||||
result = slices.DeleteFunc(fileList, func(s string) bool {
|
var delete bool = true
|
||||||
if CaseSensitive {
|
|
||||||
return !strings.Contains(s, include)
|
p := filepath.Base(s)
|
||||||
} else {
|
|
||||||
return !strings.Contains(strings.ToLower(s), strings.ToLower(include))
|
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
|
return result
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ReleaseVersion string = "0.96.1"
|
ReleaseVersion string = "0.96.2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -165,11 +165,17 @@ func serveRoot(paths []string, regexes *regexes, cache *fileCache, formats *type
|
||||||
|
|
||||||
strippedRefererUri := strings.TrimPrefix(refererUri, Prefix+mediaPrefix)
|
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{
|
filters := &filters{
|
||||||
included: splitQueryParams(r.URL.Query().Get("include"), regexes),
|
included: splitQueryParams(r.URL.Query().Get("include"), regexes),
|
||||||
excluded: splitQueryParams(r.URL.Query().Get("exclude"), 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)
|
sortOrder := sortOrder(r)
|
||||||
|
|
||||||
_, refreshInterval := refreshInterval(r)
|
_, refreshInterval := refreshInterval(r)
|
||||||
|
|
Loading…
Reference in New Issue