mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
Model refactor (#3915)
* 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
This commit is contained in:
@@ -6,12 +6,11 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/stashapp/stash/pkg/file"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/plugin"
|
||||
)
|
||||
|
||||
func (s *Service) Create(ctx context.Context, input *models.Scene, fileIDs []file.ID, coverImage []byte) (*models.Scene, error) {
|
||||
func (s *Service) Create(ctx context.Context, input *models.Scene, fileIDs []models.FileID, coverImage []byte) (*models.Scene, error) {
|
||||
// title must be set if no files are provided
|
||||
if input.Title == "" && len(fileIDs) == 0 {
|
||||
return nil, errors.New("title must be set if scene has no files")
|
||||
|
||||
@@ -105,15 +105,6 @@ func (d *FileDeleter) MarkMarkerFiles(scene *models.Scene, seconds int) error {
|
||||
return d.Files(files)
|
||||
}
|
||||
|
||||
type Destroyer interface {
|
||||
Destroy(ctx context.Context, id int) error
|
||||
}
|
||||
|
||||
type MarkerDestroyer interface {
|
||||
FindBySceneID(ctx context.Context, sceneID int) ([]*models.SceneMarker, error)
|
||||
Destroy(ctx context.Context, id int) error
|
||||
}
|
||||
|
||||
// Destroy deletes a scene and its associated relationships from the
|
||||
// database.
|
||||
func (s *Service) Destroy(ctx context.Context, scene *models.Scene, fileDeleter *FileDeleter, deleteGenerated, deleteFile bool) error {
|
||||
@@ -190,7 +181,7 @@ func (s *Service) deleteFiles(ctx context.Context, scene *models.Scene, fileDele
|
||||
// DestroyMarker deletes the scene marker from the database and returns a
|
||||
// function that removes the generated files, to be executed after the
|
||||
// transaction is successfully committed.
|
||||
func DestroyMarker(ctx context.Context, scene *models.Scene, sceneMarker *models.SceneMarker, qb MarkerDestroyer, fileDeleter *FileDeleter) error {
|
||||
func DestroyMarker(ctx context.Context, scene *models.Scene, sceneMarker *models.SceneMarker, qb models.SceneMarkerDestroyer, fileDeleter *FileDeleter) error {
|
||||
if err := qb.Destroy(ctx, sceneMarker.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -11,8 +11,6 @@ import (
|
||||
"github.com/stashapp/stash/pkg/models/json"
|
||||
"github.com/stashapp/stash/pkg/models/jsonschema"
|
||||
"github.com/stashapp/stash/pkg/sliceutil/intslice"
|
||||
"github.com/stashapp/stash/pkg/studio"
|
||||
"github.com/stashapp/stash/pkg/tag"
|
||||
"github.com/stashapp/stash/pkg/utils"
|
||||
)
|
||||
|
||||
@@ -20,18 +18,10 @@ type CoverGetter interface {
|
||||
GetCover(ctx context.Context, sceneID int) ([]byte, error)
|
||||
}
|
||||
|
||||
type MarkerTagFinder interface {
|
||||
tag.Finder
|
||||
TagFinder
|
||||
FindBySceneMarkerID(ctx context.Context, sceneMarkerID int) ([]*models.Tag, error)
|
||||
}
|
||||
|
||||
type MarkerFinder interface {
|
||||
FindBySceneID(ctx context.Context, sceneID int) ([]*models.SceneMarker, error)
|
||||
}
|
||||
|
||||
type TagFinder interface {
|
||||
models.TagGetter
|
||||
FindBySceneID(ctx context.Context, sceneID int) ([]*models.Tag, error)
|
||||
FindBySceneMarkerID(ctx context.Context, sceneMarkerID int) ([]*models.Tag, error)
|
||||
}
|
||||
|
||||
// ToBasicJSON converts a scene object into its JSON object equivalent. It
|
||||
@@ -88,7 +78,7 @@ func ToBasicJSON(ctx context.Context, reader CoverGetter, scene *models.Scene) (
|
||||
|
||||
// GetStudioName returns the name of the provided scene's studio. It returns an
|
||||
// empty string if there is no studio assigned to the scene.
|
||||
func GetStudioName(ctx context.Context, reader studio.Finder, scene *models.Scene) (string, error) {
|
||||
func GetStudioName(ctx context.Context, reader models.StudioGetter, scene *models.Scene) (string, error) {
|
||||
if scene.StudioID != nil {
|
||||
studio, err := reader.Find(ctx, *scene.StudioID)
|
||||
if err != nil {
|
||||
@@ -126,7 +116,7 @@ func getTagNames(tags []*models.Tag) []string {
|
||||
}
|
||||
|
||||
// GetDependentTagIDs returns a slice of unique tag IDs that this scene references.
|
||||
func GetDependentTagIDs(ctx context.Context, tags MarkerTagFinder, markerReader MarkerFinder, scene *models.Scene) ([]int, error) {
|
||||
func GetDependentTagIDs(ctx context.Context, tags TagFinder, markerReader models.SceneMarkerFinder, scene *models.Scene) ([]int, error) {
|
||||
var ret []int
|
||||
|
||||
t, err := tags.FindBySceneID(ctx, scene.ID)
|
||||
@@ -158,13 +148,9 @@ func GetDependentTagIDs(ctx context.Context, tags MarkerTagFinder, markerReader
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
type MovieFinder interface {
|
||||
Find(ctx context.Context, id int) (*models.Movie, error)
|
||||
}
|
||||
|
||||
// GetSceneMoviesJSON returns a slice of SceneMovie JSON representation objects
|
||||
// corresponding to the provided scene's scene movie relationships.
|
||||
func GetSceneMoviesJSON(ctx context.Context, movieReader MovieFinder, scene *models.Scene) ([]jsonschema.SceneMovie, error) {
|
||||
func GetSceneMoviesJSON(ctx context.Context, movieReader models.MovieGetter, scene *models.Scene) ([]jsonschema.SceneMovie, error) {
|
||||
sceneMovies := scene.Movies.List()
|
||||
|
||||
var results []jsonschema.SceneMovie
|
||||
@@ -202,7 +188,7 @@ func GetDependentMovieIDs(ctx context.Context, scene *models.Scene) ([]int, erro
|
||||
|
||||
// GetSceneMarkersJSON returns a slice of SceneMarker JSON representation
|
||||
// objects corresponding to the provided scene's markers.
|
||||
func GetSceneMarkersJSON(ctx context.Context, markerReader MarkerFinder, tagReader MarkerTagFinder, scene *models.Scene) ([]jsonschema.SceneMarker, error) {
|
||||
func GetSceneMarkersJSON(ctx context.Context, markerReader models.SceneMarkerFinder, tagReader TagFinder, scene *models.Scene) ([]jsonschema.SceneMarker, error) {
|
||||
sceneMarkers, err := markerReader.FindBySceneID(ctx, scene.ID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting scene markers: %v", err)
|
||||
|
||||
@@ -3,7 +3,6 @@ package scene
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/stashapp/stash/pkg/file"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/models/json"
|
||||
"github.com/stashapp/stash/pkg/models/jsonschema"
|
||||
@@ -93,9 +92,9 @@ func createFullScene(id int) models.Scene {
|
||||
Rating: &rating,
|
||||
Organized: organized,
|
||||
URLs: models.NewRelatedStrings([]string{url}),
|
||||
Files: models.NewRelatedVideoFiles([]*file.VideoFile{
|
||||
Files: models.NewRelatedVideoFiles([]*models.VideoFile{
|
||||
{
|
||||
BaseFile: &file.BaseFile{
|
||||
BaseFile: &models.BaseFile{
|
||||
Path: path,
|
||||
},
|
||||
},
|
||||
@@ -111,9 +110,9 @@ func createFullScene(id int) models.Scene {
|
||||
func createEmptyScene(id int) models.Scene {
|
||||
return models.Scene{
|
||||
ID: id,
|
||||
Files: models.NewRelatedVideoFiles([]*file.VideoFile{
|
||||
Files: models.NewRelatedVideoFiles([]*models.VideoFile{
|
||||
{
|
||||
BaseFile: &file.BaseFile{
|
||||
BaseFile: &models.BaseFile{
|
||||
Path: path,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -450,11 +450,11 @@ func (p *FilenameParser) initWhiteSpaceRegex() {
|
||||
}
|
||||
|
||||
type FilenameParserRepository struct {
|
||||
Scene Queryer
|
||||
Scene models.SceneQueryer
|
||||
Performer PerformerNamesFinder
|
||||
Studio studio.Queryer
|
||||
Studio models.StudioQueryer
|
||||
Movie MovieNameFinder
|
||||
Tag tag.Queryer
|
||||
Tag models.TagQueryer
|
||||
}
|
||||
|
||||
func (p *FilenameParser) Parse(ctx context.Context, repo FilenameParserRepository) ([]*models.SceneParserResult, int, error) {
|
||||
@@ -544,7 +544,7 @@ func (p *FilenameParser) queryPerformer(ctx context.Context, qb PerformerNamesFi
|
||||
return ret
|
||||
}
|
||||
|
||||
func (p *FilenameParser) queryStudio(ctx context.Context, qb studio.Queryer, studioName string) *models.Studio {
|
||||
func (p *FilenameParser) queryStudio(ctx context.Context, qb models.StudioQueryer, studioName string) *models.Studio {
|
||||
// massage the performer name
|
||||
studioName = delimiterRE.ReplaceAllString(studioName, " ")
|
||||
|
||||
@@ -587,7 +587,7 @@ func (p *FilenameParser) queryMovie(ctx context.Context, qb MovieNameFinder, mov
|
||||
return ret
|
||||
}
|
||||
|
||||
func (p *FilenameParser) queryTag(ctx context.Context, qb tag.Queryer, tagName string) *models.Tag {
|
||||
func (p *FilenameParser) queryTag(ctx context.Context, qb models.TagQueryer, tagName string) *models.Tag {
|
||||
// massage the tag name
|
||||
tagName = delimiterRE.ReplaceAllString(tagName, " ")
|
||||
|
||||
@@ -626,7 +626,7 @@ func (p *FilenameParser) setPerformers(ctx context.Context, qb PerformerNamesFin
|
||||
}
|
||||
}
|
||||
|
||||
func (p *FilenameParser) setTags(ctx context.Context, qb tag.Queryer, h sceneHolder, result *models.SceneParserResult) {
|
||||
func (p *FilenameParser) setTags(ctx context.Context, qb models.TagQueryer, h sceneHolder, result *models.SceneParserResult) {
|
||||
// query for each performer
|
||||
tagsSet := make(map[int]bool)
|
||||
for _, tagName := range h.tags {
|
||||
@@ -642,7 +642,7 @@ func (p *FilenameParser) setTags(ctx context.Context, qb tag.Queryer, h sceneHol
|
||||
}
|
||||
}
|
||||
|
||||
func (p *FilenameParser) setStudio(ctx context.Context, qb studio.Queryer, h sceneHolder, result *models.SceneParserResult) {
|
||||
func (p *FilenameParser) setStudio(ctx context.Context, qb models.StudioQueryer, h sceneHolder, result *models.SceneParserResult) {
|
||||
// query for each performer
|
||||
if h.studio != "" {
|
||||
studio := p.queryStudio(ctx, qb, h.studio)
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
package scene
|
||||
|
||||
import (
|
||||
"github.com/stashapp/stash/pkg/file"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
)
|
||||
|
||||
// GetHash returns the hash of the file, based on the hash algorithm provided. If
|
||||
// hash algorithm is MD5, then Checksum is returned. Otherwise, OSHash is returned.
|
||||
func GetHash(f file.File, hashAlgorithm models.HashAlgorithm) string {
|
||||
func GetHash(f models.File, hashAlgorithm models.HashAlgorithm) string {
|
||||
switch hashAlgorithm {
|
||||
case models.HashAlgorithmMd5:
|
||||
return f.Base().Fingerprints.GetString(file.FingerprintTypeMD5)
|
||||
return f.Base().Fingerprints.GetString(models.FingerprintTypeMD5)
|
||||
case models.HashAlgorithmOshash:
|
||||
return f.Base().Fingerprints.GetString(file.FingerprintTypeOshash)
|
||||
return f.Base().Fingerprints.GetString(models.FingerprintTypeOshash)
|
||||
default:
|
||||
panic("unknown hash algorithm")
|
||||
}
|
||||
|
||||
@@ -5,32 +5,25 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/stashapp/stash/pkg/file"
|
||||
"github.com/stashapp/stash/pkg/gallery"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/models/jsonschema"
|
||||
"github.com/stashapp/stash/pkg/movie"
|
||||
"github.com/stashapp/stash/pkg/performer"
|
||||
"github.com/stashapp/stash/pkg/sliceutil/stringslice"
|
||||
"github.com/stashapp/stash/pkg/studio"
|
||||
"github.com/stashapp/stash/pkg/tag"
|
||||
"github.com/stashapp/stash/pkg/utils"
|
||||
)
|
||||
|
||||
type FullCreatorUpdater interface {
|
||||
CreatorUpdater
|
||||
Update(ctx context.Context, updatedScene *models.Scene) error
|
||||
Updater
|
||||
type ImporterReaderWriter interface {
|
||||
models.SceneCreatorUpdater
|
||||
FindByFileID(ctx context.Context, fileID models.FileID) ([]*models.Scene, error)
|
||||
}
|
||||
|
||||
type Importer struct {
|
||||
ReaderWriter FullCreatorUpdater
|
||||
FileFinder file.Getter
|
||||
StudioWriter studio.NameFinderCreator
|
||||
GalleryFinder gallery.Finder
|
||||
PerformerWriter performer.NameFinderCreator
|
||||
MovieWriter movie.NameFinderCreator
|
||||
TagWriter tag.NameFinderCreator
|
||||
ReaderWriter ImporterReaderWriter
|
||||
FileFinder models.FileFinder
|
||||
StudioWriter models.StudioFinderCreator
|
||||
GalleryFinder models.GalleryFinder
|
||||
PerformerWriter models.PerformerFinderCreator
|
||||
MovieWriter models.MovieFinderCreator
|
||||
TagWriter models.TagFinderCreator
|
||||
Input jsonschema.Scene
|
||||
MissingRefBehaviour models.ImportMissingRefEnum
|
||||
FileNamingAlgorithm models.HashAlgorithm
|
||||
@@ -123,7 +116,7 @@ func (i *Importer) sceneJSONToScene(sceneJSON jsonschema.Scene) models.Scene {
|
||||
}
|
||||
|
||||
func (i *Importer) populateFiles(ctx context.Context) error {
|
||||
files := make([]*file.VideoFile, 0)
|
||||
files := make([]*models.VideoFile, 0)
|
||||
|
||||
for _, ref := range i.Input.Files {
|
||||
path := ref
|
||||
@@ -135,7 +128,7 @@ func (i *Importer) populateFiles(ctx context.Context) error {
|
||||
if f == nil {
|
||||
return fmt.Errorf("scene file '%s' not found", path)
|
||||
} else {
|
||||
files = append(files, f.(*file.VideoFile))
|
||||
files = append(files, f.(*models.VideoFile))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -413,7 +406,7 @@ func (i *Importer) FindExistingID(ctx context.Context) (*int, error) {
|
||||
}
|
||||
|
||||
func (i *Importer) Create(ctx context.Context) (*int, error) {
|
||||
var fileIDs []file.ID
|
||||
var fileIDs []models.FileID
|
||||
for _, f := range i.scene.Files.List() {
|
||||
fileIDs = append(fileIDs, f.Base().ID)
|
||||
}
|
||||
@@ -437,7 +430,7 @@ func (i *Importer) Update(ctx context.Context, id int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func importTags(ctx context.Context, tagWriter tag.NameFinderCreator, names []string, missingRefBehaviour models.ImportMissingRefEnum) ([]*models.Tag, error) {
|
||||
func importTags(ctx context.Context, tagWriter models.TagFinderCreator, names []string, missingRefBehaviour models.ImportMissingRefEnum) ([]*models.Tag, error) {
|
||||
tags, err := tagWriter.FindByNames(ctx, names, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -472,7 +465,7 @@ func importTags(ctx context.Context, tagWriter tag.NameFinderCreator, names []st
|
||||
return tags, nil
|
||||
}
|
||||
|
||||
func createTags(ctx context.Context, tagWriter tag.NameFinderCreator, names []string) ([]*models.Tag, error) {
|
||||
func createTags(ctx context.Context, tagWriter models.TagCreator, names []string) ([]*models.Tag, error) {
|
||||
var ret []*models.Tag
|
||||
for _, name := range names {
|
||||
newTag := models.NewTag(name)
|
||||
|
||||
@@ -7,20 +7,17 @@ import (
|
||||
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/models/jsonschema"
|
||||
"github.com/stashapp/stash/pkg/tag"
|
||||
)
|
||||
|
||||
type MarkerCreatorUpdater interface {
|
||||
Create(ctx context.Context, newSceneMarker *models.SceneMarker) error
|
||||
Update(ctx context.Context, updatedSceneMarker *models.SceneMarker) error
|
||||
models.SceneMarkerCreatorUpdater
|
||||
FindBySceneID(ctx context.Context, sceneID int) ([]*models.SceneMarker, error)
|
||||
UpdateTags(ctx context.Context, markerID int, tagIDs []int) error
|
||||
}
|
||||
|
||||
type MarkerImporter struct {
|
||||
SceneID int
|
||||
ReaderWriter MarkerCreatorUpdater
|
||||
TagWriter tag.NameFinderCreator
|
||||
TagWriter models.TagFinderCreator
|
||||
Input jsonschema.SceneMarker
|
||||
MissingRefBehaviour models.ImportMissingRefEnum
|
||||
|
||||
|
||||
@@ -7,15 +7,7 @@ import (
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
)
|
||||
|
||||
type MarkerQueryer interface {
|
||||
Query(ctx context.Context, sceneMarkerFilter *models.SceneMarkerFilterType, findFilter *models.FindFilterType) ([]*models.SceneMarker, int, error)
|
||||
}
|
||||
|
||||
type MarkerCountQueryer interface {
|
||||
QueryCount(ctx context.Context, sceneMarkerFilter *models.SceneMarkerFilterType, findFilter *models.FindFilterType) (int, error)
|
||||
}
|
||||
|
||||
func MarkerCountByTagID(ctx context.Context, r MarkerCountQueryer, id int, depth *int) (int, error) {
|
||||
func MarkerCountByTagID(ctx context.Context, r models.SceneMarkerQueryer, id int, depth *int) (int, error) {
|
||||
filter := &models.SceneMarkerFilterType{
|
||||
Tags: &models.HierarchicalMultiCriterionInput{
|
||||
Value: []string{strconv.Itoa(id)},
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/stashapp/stash/pkg/file"
|
||||
"github.com/stashapp/stash/pkg/fsutil"
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
@@ -33,7 +32,7 @@ func (s *Service) Merge(ctx context.Context, sourceIDs []int, destinationID int,
|
||||
return fmt.Errorf("finding source scenes: %w", err)
|
||||
}
|
||||
|
||||
var fileIDs []file.ID
|
||||
var fileIDs []models.FileID
|
||||
|
||||
for _, src := range sources {
|
||||
// TODO - delete generated files as needed
|
||||
|
||||
@@ -20,7 +20,8 @@ type MigrateSceneScreenshotsInput struct {
|
||||
type HashFinderCoverUpdater interface {
|
||||
FindByChecksum(ctx context.Context, checksum string) ([]*models.Scene, error)
|
||||
FindByOSHash(ctx context.Context, oshash string) ([]*models.Scene, error)
|
||||
CoverUpdater
|
||||
HasCover(ctx context.Context, sceneID int) (bool, error)
|
||||
UpdateCover(ctx context.Context, sceneID int, cover []byte) error
|
||||
}
|
||||
|
||||
type ScreenshotMigrator struct {
|
||||
|
||||
@@ -11,19 +11,6 @@ import (
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
)
|
||||
|
||||
type Queryer interface {
|
||||
Query(ctx context.Context, options models.SceneQueryOptions) (*models.SceneQueryResult, error)
|
||||
}
|
||||
|
||||
type CountQueryer interface {
|
||||
QueryCount(ctx context.Context, sceneFilter *models.SceneFilterType, findFilter *models.FindFilterType) (int, error)
|
||||
}
|
||||
|
||||
type IDFinder interface {
|
||||
Find(ctx context.Context, id int) (*models.Scene, error)
|
||||
FindMany(ctx context.Context, ids []int) ([]*models.Scene, error)
|
||||
}
|
||||
|
||||
// QueryOptions returns a SceneQueryOptions populated with the provided filters.
|
||||
func QueryOptions(sceneFilter *models.SceneFilterType, findFilter *models.FindFilterType, count bool) models.SceneQueryOptions {
|
||||
return models.SceneQueryOptions{
|
||||
@@ -36,7 +23,7 @@ func QueryOptions(sceneFilter *models.SceneFilterType, findFilter *models.FindFi
|
||||
}
|
||||
|
||||
// QueryWithCount queries for scenes, returning the scene objects and the total count.
|
||||
func QueryWithCount(ctx context.Context, qb Queryer, sceneFilter *models.SceneFilterType, findFilter *models.FindFilterType) ([]*models.Scene, int, error) {
|
||||
func QueryWithCount(ctx context.Context, qb models.SceneQueryer, sceneFilter *models.SceneFilterType, findFilter *models.FindFilterType) ([]*models.Scene, int, error) {
|
||||
// this was moved from the queryBuilder code
|
||||
// left here so that calling functions can reference this instead
|
||||
result, err := qb.Query(ctx, QueryOptions(sceneFilter, findFilter, true))
|
||||
@@ -53,7 +40,7 @@ func QueryWithCount(ctx context.Context, qb Queryer, sceneFilter *models.SceneFi
|
||||
}
|
||||
|
||||
// Query queries for scenes using the provided filters.
|
||||
func Query(ctx context.Context, qb Queryer, sceneFilter *models.SceneFilterType, findFilter *models.FindFilterType) ([]*models.Scene, error) {
|
||||
func Query(ctx context.Context, qb models.SceneQueryer, sceneFilter *models.SceneFilterType, findFilter *models.FindFilterType) ([]*models.Scene, error) {
|
||||
result, err := qb.Query(ctx, QueryOptions(sceneFilter, findFilter, false))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -67,7 +54,7 @@ func Query(ctx context.Context, qb Queryer, sceneFilter *models.SceneFilterType,
|
||||
return scenes, nil
|
||||
}
|
||||
|
||||
func BatchProcess(ctx context.Context, reader Queryer, sceneFilter *models.SceneFilterType, findFilter *models.FindFilterType, fn func(scene *models.Scene) error) error {
|
||||
func BatchProcess(ctx context.Context, reader models.SceneQueryer, sceneFilter *models.SceneFilterType, findFilter *models.FindFilterType, fn func(scene *models.Scene) error) error {
|
||||
const batchSize = 1000
|
||||
|
||||
if findFilter == nil {
|
||||
@@ -134,7 +121,7 @@ func FilterFromPaths(paths []string) *models.SceneFilterType {
|
||||
return ret
|
||||
}
|
||||
|
||||
func CountByStudioID(ctx context.Context, r CountQueryer, id int, depth *int) (int, error) {
|
||||
func CountByStudioID(ctx context.Context, r models.SceneQueryer, id int, depth *int) (int, error) {
|
||||
filter := &models.SceneFilterType{
|
||||
Studios: &models.HierarchicalMultiCriterionInput{
|
||||
Value: []string{strconv.Itoa(id)},
|
||||
@@ -146,7 +133,7 @@ func CountByStudioID(ctx context.Context, r CountQueryer, id int, depth *int) (i
|
||||
return r.QueryCount(ctx, filter, nil)
|
||||
}
|
||||
|
||||
func CountByTagID(ctx context.Context, r CountQueryer, id int, depth *int) (int, error) {
|
||||
func CountByTagID(ctx context.Context, r models.SceneQueryer, id int, depth *int) (int, error) {
|
||||
filter := &models.SceneFilterType{
|
||||
Tags: &models.HierarchicalMultiCriterionInput{
|
||||
Value: []string{strconv.Itoa(id)},
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/stashapp/stash/pkg/file"
|
||||
"github.com/stashapp/stash/pkg/file/video"
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
@@ -19,21 +18,22 @@ var (
|
||||
ErrNotVideoFile = errors.New("not a video file")
|
||||
)
|
||||
|
||||
type CreatorUpdater interface {
|
||||
FindByFileID(ctx context.Context, fileID file.ID) ([]*models.Scene, error)
|
||||
FindByFingerprints(ctx context.Context, fp []file.Fingerprint) ([]*models.Scene, error)
|
||||
Creator
|
||||
type ScanCreatorUpdater interface {
|
||||
FindByFileID(ctx context.Context, fileID models.FileID) ([]*models.Scene, error)
|
||||
FindByFingerprints(ctx context.Context, fp []models.Fingerprint) ([]*models.Scene, error)
|
||||
GetFiles(ctx context.Context, relatedID int) ([]*models.VideoFile, error)
|
||||
|
||||
Create(ctx context.Context, newScene *models.Scene, fileIDs []models.FileID) error
|
||||
UpdatePartial(ctx context.Context, id int, updatedScene models.ScenePartial) (*models.Scene, error)
|
||||
AddFileID(ctx context.Context, id int, fileID file.ID) error
|
||||
models.VideoFileLoader
|
||||
AddFileID(ctx context.Context, id int, fileID models.FileID) error
|
||||
}
|
||||
|
||||
type ScanGenerator interface {
|
||||
Generate(ctx context.Context, s *models.Scene, f *file.VideoFile) error
|
||||
Generate(ctx context.Context, s *models.Scene, f *models.VideoFile) error
|
||||
}
|
||||
|
||||
type ScanHandler struct {
|
||||
CreatorUpdater CreatorUpdater
|
||||
CreatorUpdater ScanCreatorUpdater
|
||||
|
||||
ScanGenerator ScanGenerator
|
||||
CaptionUpdater video.CaptionUpdater
|
||||
@@ -63,12 +63,12 @@ func (h *ScanHandler) validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *ScanHandler) Handle(ctx context.Context, f file.File, oldFile file.File) error {
|
||||
func (h *ScanHandler) Handle(ctx context.Context, f models.File, oldFile models.File) error {
|
||||
if err := h.validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
videoFile, ok := f.(*file.VideoFile)
|
||||
videoFile, ok := f.(*models.VideoFile)
|
||||
if !ok {
|
||||
return ErrNotVideoFile
|
||||
}
|
||||
@@ -108,7 +108,7 @@ func (h *ScanHandler) Handle(ctx context.Context, f file.File, oldFile file.File
|
||||
|
||||
logger.Infof("%s doesn't exist. Creating new scene...", f.Base().Path)
|
||||
|
||||
if err := h.CreatorUpdater.Create(ctx, newScene, []file.ID{videoFile.ID}); err != nil {
|
||||
if err := h.CreatorUpdater.Create(ctx, newScene, []models.FileID{videoFile.ID}); err != nil {
|
||||
return fmt.Errorf("creating new scene: %w", err)
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ func (h *ScanHandler) Handle(ctx context.Context, f file.File, oldFile file.File
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *ScanHandler) associateExisting(ctx context.Context, existing []*models.Scene, f *file.VideoFile, updateExisting bool) error {
|
||||
func (h *ScanHandler) associateExisting(ctx context.Context, existing []*models.Scene, f *models.VideoFile, updateExisting bool) error {
|
||||
for _, s := range existing {
|
||||
if err := s.LoadFiles(ctx, h.CreatorUpdater); err != nil {
|
||||
return err
|
||||
|
||||
@@ -1,58 +1,19 @@
|
||||
package scene
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/stashapp/stash/pkg/file"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/models/paths"
|
||||
"github.com/stashapp/stash/pkg/plugin"
|
||||
)
|
||||
|
||||
type FinderByFile interface {
|
||||
FindByFileID(ctx context.Context, fileID file.ID) ([]*models.Scene, error)
|
||||
}
|
||||
|
||||
type FileAssigner interface {
|
||||
AssignFiles(ctx context.Context, sceneID int, fileID []file.ID) error
|
||||
}
|
||||
|
||||
type Creator interface {
|
||||
Create(ctx context.Context, newScene *models.Scene, fileIDs []file.ID) error
|
||||
}
|
||||
|
||||
type CoverUpdater interface {
|
||||
HasCover(ctx context.Context, sceneID int) (bool, error)
|
||||
UpdateCover(ctx context.Context, sceneID int, cover []byte) error
|
||||
}
|
||||
|
||||
type Config interface {
|
||||
GetVideoFileNamingAlgorithm() models.HashAlgorithm
|
||||
}
|
||||
|
||||
type Repository interface {
|
||||
IDFinder
|
||||
FinderByFile
|
||||
Creator
|
||||
PartialUpdater
|
||||
Destroyer
|
||||
models.VideoFileLoader
|
||||
FileAssigner
|
||||
CoverUpdater
|
||||
models.SceneReader
|
||||
}
|
||||
|
||||
type MarkerRepository interface {
|
||||
MarkerFinder
|
||||
MarkerDestroyer
|
||||
|
||||
Update(ctx context.Context, updatedObject *models.SceneMarker) error
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
File file.Store
|
||||
Repository Repository
|
||||
MarkerRepository MarkerRepository
|
||||
File models.FileReaderWriter
|
||||
Repository models.SceneReaderWriter
|
||||
MarkerRepository models.SceneMarkerReaderWriter
|
||||
PluginCache *plugin.Cache
|
||||
|
||||
Paths *paths.Paths
|
||||
|
||||
@@ -6,20 +6,10 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/stashapp/stash/pkg/file"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/utils"
|
||||
)
|
||||
|
||||
type Updater interface {
|
||||
PartialUpdater
|
||||
UpdateCover(ctx context.Context, sceneID int, cover []byte) error
|
||||
}
|
||||
|
||||
type PartialUpdater interface {
|
||||
UpdatePartial(ctx context.Context, id int, updatedScene models.ScenePartial) (*models.Scene, error)
|
||||
}
|
||||
|
||||
var ErrEmptyUpdater = errors.New("no fields have been set")
|
||||
|
||||
// UpdateSet is used to update a scene and its relationships.
|
||||
@@ -46,7 +36,7 @@ func (u *UpdateSet) IsEmpty() bool {
|
||||
// Update updates a scene by updating the fields in the Partial field, then
|
||||
// updates non-nil relationships. Returns an error if there is no work to
|
||||
// be done.
|
||||
func (u *UpdateSet) Update(ctx context.Context, qb Updater) (*models.Scene, error) {
|
||||
func (u *UpdateSet) Update(ctx context.Context, qb models.SceneUpdater) (*models.Scene, error) {
|
||||
if u.IsEmpty() {
|
||||
return nil, ErrEmptyUpdater
|
||||
}
|
||||
@@ -83,7 +73,7 @@ func (u UpdateSet) UpdateInput() models.SceneUpdateInput {
|
||||
return ret
|
||||
}
|
||||
|
||||
func AddPerformer(ctx context.Context, qb PartialUpdater, o *models.Scene, performerID int) error {
|
||||
func AddPerformer(ctx context.Context, qb models.SceneUpdater, o *models.Scene, performerID int) error {
|
||||
_, err := qb.UpdatePartial(ctx, o.ID, models.ScenePartial{
|
||||
PerformerIDs: &models.UpdateIDs{
|
||||
IDs: []int{performerID},
|
||||
@@ -93,7 +83,7 @@ func AddPerformer(ctx context.Context, qb PartialUpdater, o *models.Scene, perfo
|
||||
return err
|
||||
}
|
||||
|
||||
func AddTag(ctx context.Context, qb PartialUpdater, o *models.Scene, tagID int) error {
|
||||
func AddTag(ctx context.Context, qb models.SceneUpdater, o *models.Scene, tagID int) error {
|
||||
_, err := qb.UpdatePartial(ctx, o.ID, models.ScenePartial{
|
||||
TagIDs: &models.UpdateIDs{
|
||||
IDs: []int{tagID},
|
||||
@@ -103,7 +93,7 @@ func AddTag(ctx context.Context, qb PartialUpdater, o *models.Scene, tagID int)
|
||||
return err
|
||||
}
|
||||
|
||||
func AddGallery(ctx context.Context, qb PartialUpdater, o *models.Scene, galleryID int) error {
|
||||
func AddGallery(ctx context.Context, qb models.SceneUpdater, o *models.Scene, galleryID int) error {
|
||||
_, err := qb.UpdatePartial(ctx, o.ID, models.ScenePartial{
|
||||
TagIDs: &models.UpdateIDs{
|
||||
IDs: []int{galleryID},
|
||||
@@ -113,7 +103,7 @@ func AddGallery(ctx context.Context, qb PartialUpdater, o *models.Scene, gallery
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *Service) AssignFile(ctx context.Context, sceneID int, fileID file.ID) error {
|
||||
func (s *Service) AssignFile(ctx context.Context, sceneID int, fileID models.FileID) error {
|
||||
// ensure file isn't a primary file and that it is a video file
|
||||
f, err := s.File.Find(ctx, fileID)
|
||||
if err != nil {
|
||||
@@ -121,7 +111,7 @@ func (s *Service) AssignFile(ctx context.Context, sceneID int, fileID file.ID) e
|
||||
}
|
||||
|
||||
ff := f[0]
|
||||
if _, ok := ff.(*file.VideoFile); !ok {
|
||||
if _, ok := ff.(*models.VideoFile); !ok {
|
||||
return fmt.Errorf("%s is not a video file", ff.Base().Path)
|
||||
}
|
||||
|
||||
@@ -134,5 +124,5 @@ func (s *Service) AssignFile(ctx context.Context, sceneID int, fileID file.ID) e
|
||||
return errors.New("cannot reassign primary file")
|
||||
}
|
||||
|
||||
return s.Repository.AssignFiles(ctx, sceneID, []file.ID{fileID})
|
||||
return s.Repository.AssignFiles(ctx, sceneID, []models.FileID{fileID})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user