stash/pkg/sqlite/criterion_handlers.go
keenbed 14bde44597
added support for image orientation filter (#4404)
* added support for image orientation filter
* Add orientation filtering to scenes
---------
Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
2024-01-16 13:50:17 +11:00

43 lines
952 B
Go

package sqlite
import (
"context"
"fmt"
"github.com/stashapp/stash/pkg/models"
)
// shared criterion handlers go here
func orientationCriterionHandler(orientation *models.OrientationCriterionInput, heightColumn string, widthColumn string, addJoinFn func(f *filterBuilder)) criterionHandlerFunc {
return func(ctx context.Context, f *filterBuilder) {
if orientation != nil {
if addJoinFn != nil {
addJoinFn(f)
}
var clauses []sqlClause
for _, v := range orientation.Value {
// width mod height
mod := ""
switch v {
case models.OrientationPortrait:
mod = "<"
case models.OrientationLandscape:
mod = ">"
case models.OrientationSquare:
mod = "="
}
if mod != "" {
clauses = append(clauses, makeClause(fmt.Sprintf("%s %s %s", widthColumn, mod, heightColumn)))
}
}
if len(clauses) > 0 {
f.whereClauses = append(f.whereClauses, orClauses(clauses...))
}
}
}
}