mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
Add filtering to folder select (#4277)
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/text/collate"
|
||||
)
|
||||
@@ -25,13 +26,27 @@ func (s dirLister) Bytes(i int) []byte {
|
||||
// listDir will return the contents of a given directory path as a string slice
|
||||
func listDir(col *collate.Collator, path string) ([]string, error) {
|
||||
var dirPaths []string
|
||||
dirPath := path
|
||||
|
||||
files, err := os.ReadDir(path)
|
||||
if err != nil {
|
||||
path = filepath.Dir(path)
|
||||
files, err = os.ReadDir(path)
|
||||
dirPath = filepath.Dir(path)
|
||||
dirFiles, err := os.ReadDir(dirPath)
|
||||
if err != nil {
|
||||
return dirPaths, err
|
||||
}
|
||||
|
||||
// Filter dir contents by last path fragment if the dir isn't an exact match
|
||||
base := strings.ToLower(filepath.Base(path))
|
||||
if base != "." && base != string(filepath.Separator) {
|
||||
for _, file := range dirFiles {
|
||||
if strings.HasPrefix(strings.ToLower(file.Name()), base) {
|
||||
files = append(files, file)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
files = dirFiles
|
||||
}
|
||||
}
|
||||
|
||||
if col != nil {
|
||||
@@ -42,7 +57,7 @@ func listDir(col *collate.Collator, path string) ([]string, error) {
|
||||
if !file.IsDir() {
|
||||
continue
|
||||
}
|
||||
dirPaths = append(dirPaths, filepath.Join(path, file.Name()))
|
||||
dirPaths = append(dirPaths, filepath.Join(dirPath, file.Name()))
|
||||
}
|
||||
return dirPaths, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user