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>
This commit is contained in:
keenbed
2024-01-16 03:50:17 +01:00
committed by GitHub
parent aeb68a5851
commit 14bde44597
14 changed files with 157 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
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...))
}
}
}
}