mirror of
https://github.com/stashapp/stash.git
synced 2025-12-06 08:26:00 +01:00
* Add mockery config file * Move basic file/folder structs to models * Fix hack due to import loop * Move file interfaces to models * Move folder interfaces to models * Move scene interfaces to models * Move scene marker interfaces to models * Move image interfaces to models * Move gallery interfaces to models * Move gallery chapter interfaces to models * Move studio interfaces to models * Move movie interfaces to models * Move performer interfaces to models * Move tag interfaces to models * Move autotag interfaces to models * Regenerate mocks
78 lines
1.3 KiB
Go
78 lines
1.3 KiB
Go
package models
|
|
|
|
import (
|
|
"context"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
type FileQueryOptions struct {
|
|
QueryOptions
|
|
FileFilter *FileFilterType
|
|
}
|
|
|
|
type FileFilterType struct {
|
|
And *FileFilterType `json:"AND"`
|
|
Or *FileFilterType `json:"OR"`
|
|
Not *FileFilterType `json:"NOT"`
|
|
|
|
// Filter by path
|
|
Path *StringCriterionInput `json:"path"`
|
|
}
|
|
|
|
func PathsFileFilter(paths []string) *FileFilterType {
|
|
if paths == nil {
|
|
return nil
|
|
}
|
|
|
|
sep := string(filepath.Separator)
|
|
|
|
var ret *FileFilterType
|
|
var or *FileFilterType
|
|
for _, p := range paths {
|
|
newOr := &FileFilterType{}
|
|
if or != nil {
|
|
or.Or = newOr
|
|
} else {
|
|
ret = newOr
|
|
}
|
|
|
|
or = newOr
|
|
|
|
if !strings.HasSuffix(p, sep) {
|
|
p += sep
|
|
}
|
|
|
|
or.Path = &StringCriterionInput{
|
|
Modifier: CriterionModifierEquals,
|
|
Value: p + "%",
|
|
}
|
|
}
|
|
|
|
return ret
|
|
}
|
|
|
|
type FileQueryResult struct {
|
|
// can't use QueryResult because id type is wrong
|
|
|
|
IDs []FileID
|
|
Count int
|
|
|
|
getter FileGetter
|
|
files []File
|
|
resolveErr error
|
|
}
|
|
|
|
func NewFileQueryResult(fileGetter FileGetter) *FileQueryResult {
|
|
return &FileQueryResult{
|
|
getter: fileGetter,
|
|
}
|
|
}
|
|
|
|
func (r *FileQueryResult) Resolve(ctx context.Context) ([]File, error) {
|
|
// cache results
|
|
if r.files == nil && r.resolveErr == nil {
|
|
r.files, r.resolveErr = r.getter.Find(ctx, r.IDs...)
|
|
}
|
|
return r.files, r.resolveErr
|
|
}
|