stash/pkg/api/resolver_query_find_scene.go

79 lines
2.0 KiB
Go
Raw Normal View History

2019-02-09 12:30:49 +00:00
package api
import (
"context"
"strconv"
"github.com/stashapp/stash/pkg/manager"
"github.com/stashapp/stash/pkg/models"
2019-02-09 12:30:49 +00:00
)
func (r *queryResolver) FindScene(ctx context.Context, id *string, checksum *string) (*models.Scene, error) {
qb := models.NewSceneQueryBuilder()
var scene *models.Scene
var err error
if id != nil {
idInt, _ := strconv.Atoi(*id)
2019-02-09 12:30:49 +00:00
scene, err = qb.Find(idInt)
} else if checksum != nil {
scene, err = qb.FindByChecksum(*checksum)
}
return scene, err
}
2020-08-06 01:21:14 +00:00
func (r *queryResolver) FindSceneByHash(ctx context.Context, input models.SceneHashInput) (*models.Scene, error) {
qb := models.NewSceneQueryBuilder()
var scene *models.Scene
var err error
if input.Checksum != nil {
scene, err = qb.FindByChecksum(*input.Checksum)
if err != nil {
return nil, err
}
}
if scene == nil && input.Oshash != nil {
scene, err = qb.FindByOSHash(*input.Oshash)
if err != nil {
return nil, err
}
}
return scene, err
}
func (r *queryResolver) FindScenes(ctx context.Context, sceneFilter *models.SceneFilterType, sceneIds []int, filter *models.FindFilterType) (*models.FindScenesResultType, error) {
2019-02-09 12:30:49 +00:00
qb := models.NewSceneQueryBuilder()
scenes, total := qb.Query(sceneFilter, filter)
return &models.FindScenesResultType{
Count: total,
2019-02-09 12:30:49 +00:00
Scenes: scenes,
}, nil
}
func (r *queryResolver) FindScenesByPathRegex(ctx context.Context, filter *models.FindFilterType) (*models.FindScenesResultType, error) {
qb := models.NewSceneQueryBuilder()
scenes, total := qb.QueryByPathRegex(filter)
return &models.FindScenesResultType{
Count: total,
Scenes: scenes,
}, nil
}
func (r *queryResolver) ParseSceneFilenames(ctx context.Context, filter *models.FindFilterType, config models.SceneParserInput) (*models.SceneParserResultType, error) {
parser := manager.NewSceneFilenameParser(filter, config)
result, count, err := parser.Parse()
if err != nil {
return nil, err
}
return &models.SceneParserResultType{
Count: count,
Results: result,
}, nil
}