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:
@@ -20,14 +20,14 @@ const (
|
||||
type autotagScraper struct {
|
||||
// repository models.Repository
|
||||
txnManager txn.Manager
|
||||
performerReader match.PerformerAutoTagQueryer
|
||||
studioReader match.StudioAutoTagQueryer
|
||||
tagReader match.TagAutoTagQueryer
|
||||
performerReader models.PerformerAutoTagQueryer
|
||||
studioReader models.StudioAutoTagQueryer
|
||||
tagReader models.TagAutoTagQueryer
|
||||
|
||||
globalConfig GlobalConfig
|
||||
}
|
||||
|
||||
func autotagMatchPerformers(ctx context.Context, path string, performerReader match.PerformerAutoTagQueryer, trimExt bool) ([]*models.ScrapedPerformer, error) {
|
||||
func autotagMatchPerformers(ctx context.Context, path string, performerReader models.PerformerAutoTagQueryer, trimExt bool) ([]*models.ScrapedPerformer, error) {
|
||||
p, err := match.PathToPerformers(ctx, path, performerReader, nil, trimExt)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error matching performers: %w", err)
|
||||
@@ -52,7 +52,7 @@ func autotagMatchPerformers(ctx context.Context, path string, performerReader ma
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func autotagMatchStudio(ctx context.Context, path string, studioReader match.StudioAutoTagQueryer, trimExt bool) (*models.ScrapedStudio, error) {
|
||||
func autotagMatchStudio(ctx context.Context, path string, studioReader models.StudioAutoTagQueryer, trimExt bool) (*models.ScrapedStudio, error) {
|
||||
studio, err := match.PathToStudio(ctx, path, studioReader, nil, trimExt)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error matching studios: %w", err)
|
||||
@@ -69,7 +69,7 @@ func autotagMatchStudio(ctx context.Context, path string, studioReader match.Stu
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func autotagMatchTags(ctx context.Context, path string, tagReader match.TagAutoTagQueryer, trimExt bool) ([]*models.ScrapedTag, error) {
|
||||
func autotagMatchTags(ctx context.Context, path string, tagReader models.TagAutoTagQueryer, trimExt bool) ([]*models.ScrapedTag, error) {
|
||||
t, err := match.PathToTags(ctx, path, tagReader, nil, trimExt)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error matching tags: %w", err)
|
||||
|
||||
@@ -15,8 +15,6 @@ import (
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
"github.com/stashapp/stash/pkg/match"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/scene"
|
||||
"github.com/stashapp/stash/pkg/tag"
|
||||
"github.com/stashapp/stash/pkg/txn"
|
||||
)
|
||||
|
||||
@@ -53,27 +51,27 @@ func isCDPPathWS(c GlobalConfig) bool {
|
||||
}
|
||||
|
||||
type SceneFinder interface {
|
||||
scene.IDFinder
|
||||
models.SceneGetter
|
||||
models.URLLoader
|
||||
}
|
||||
|
||||
type PerformerFinder interface {
|
||||
match.PerformerAutoTagQueryer
|
||||
models.PerformerAutoTagQueryer
|
||||
match.PerformerFinder
|
||||
}
|
||||
|
||||
type StudioFinder interface {
|
||||
match.StudioAutoTagQueryer
|
||||
match.StudioFinder
|
||||
models.StudioAutoTagQueryer
|
||||
FindByStashID(ctx context.Context, stashID models.StashID) ([]*models.Studio, error)
|
||||
}
|
||||
|
||||
type TagFinder interface {
|
||||
match.TagAutoTagQueryer
|
||||
tag.Queryer
|
||||
models.TagGetter
|
||||
models.TagAutoTagQueryer
|
||||
}
|
||||
|
||||
type GalleryFinder interface {
|
||||
Find(ctx context.Context, id int) (*models.Gallery, error)
|
||||
models.GalleryGetter
|
||||
models.FileLoader
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
"github.com/stashapp/stash/pkg/match"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/tag"
|
||||
"github.com/stashapp/stash/pkg/txn"
|
||||
)
|
||||
|
||||
@@ -201,7 +200,7 @@ func (c Cache) postScrapeGallery(ctx context.Context, g ScrapedGallery) (Scraped
|
||||
return g, nil
|
||||
}
|
||||
|
||||
func postProcessTags(ctx context.Context, tqb tag.Queryer, scrapedTags []*models.ScrapedTag) ([]*models.ScrapedTag, error) {
|
||||
func postProcessTags(ctx context.Context, tqb models.TagQueryer, scrapedTags []*models.ScrapedTag) ([]*models.ScrapedTag, error) {
|
||||
var ret []*models.ScrapedTag
|
||||
|
||||
for _, t := range scrapedTags {
|
||||
|
||||
@@ -19,41 +19,39 @@ import (
|
||||
|
||||
"github.com/Yamashou/gqlgenc/graphqljson"
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/stashapp/stash/pkg/file"
|
||||
"github.com/stashapp/stash/pkg/logger"
|
||||
"github.com/stashapp/stash/pkg/match"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/scraper"
|
||||
"github.com/stashapp/stash/pkg/scraper/stashbox/graphql"
|
||||
"github.com/stashapp/stash/pkg/sliceutil/stringslice"
|
||||
"github.com/stashapp/stash/pkg/studio"
|
||||
"github.com/stashapp/stash/pkg/tag"
|
||||
"github.com/stashapp/stash/pkg/txn"
|
||||
"github.com/stashapp/stash/pkg/utils"
|
||||
)
|
||||
|
||||
type SceneReader interface {
|
||||
Find(ctx context.Context, id int) (*models.Scene, error)
|
||||
models.SceneGetter
|
||||
models.StashIDLoader
|
||||
models.VideoFileLoader
|
||||
}
|
||||
|
||||
type PerformerReader interface {
|
||||
models.PerformerGetter
|
||||
match.PerformerFinder
|
||||
Find(ctx context.Context, id int) (*models.Performer, error)
|
||||
FindBySceneID(ctx context.Context, sceneID int) ([]*models.Performer, error)
|
||||
models.AliasLoader
|
||||
models.StashIDLoader
|
||||
FindBySceneID(ctx context.Context, sceneID int) ([]*models.Performer, error)
|
||||
GetImage(ctx context.Context, performerID int) ([]byte, error)
|
||||
}
|
||||
|
||||
type StudioReader interface {
|
||||
models.StudioGetter
|
||||
match.StudioFinder
|
||||
studio.Finder
|
||||
models.StashIDLoader
|
||||
}
|
||||
|
||||
type TagFinder interface {
|
||||
tag.Queryer
|
||||
models.TagQueryer
|
||||
FindBySceneID(ctx context.Context, sceneID int) ([]*models.Tag, error)
|
||||
}
|
||||
|
||||
@@ -151,7 +149,7 @@ func (c Client) FindStashBoxScenesByFingerprints(ctx context.Context, ids []int)
|
||||
var sceneFPs []*graphql.FingerprintQueryInput
|
||||
|
||||
for _, f := range scene.Files.List() {
|
||||
checksum := f.Fingerprints.GetString(file.FingerprintTypeMD5)
|
||||
checksum := f.Fingerprints.GetString(models.FingerprintTypeMD5)
|
||||
if checksum != "" {
|
||||
sceneFPs = append(sceneFPs, &graphql.FingerprintQueryInput{
|
||||
Hash: checksum,
|
||||
@@ -159,7 +157,7 @@ func (c Client) FindStashBoxScenesByFingerprints(ctx context.Context, ids []int)
|
||||
})
|
||||
}
|
||||
|
||||
oshash := f.Fingerprints.GetString(file.FingerprintTypeOshash)
|
||||
oshash := f.Fingerprints.GetString(models.FingerprintTypeOshash)
|
||||
if oshash != "" {
|
||||
sceneFPs = append(sceneFPs, &graphql.FingerprintQueryInput{
|
||||
Hash: oshash,
|
||||
@@ -167,7 +165,7 @@ func (c Client) FindStashBoxScenesByFingerprints(ctx context.Context, ids []int)
|
||||
})
|
||||
}
|
||||
|
||||
phash := f.Fingerprints.GetInt64(file.FingerprintTypePhash)
|
||||
phash := f.Fingerprints.GetInt64(models.FingerprintTypePhash)
|
||||
if phash != 0 {
|
||||
phashStr := utils.PhashToString(phash)
|
||||
sceneFPs = append(sceneFPs, &graphql.FingerprintQueryInput{
|
||||
@@ -279,7 +277,7 @@ func (c Client) SubmitStashBoxFingerprints(ctx context.Context, sceneIDs []strin
|
||||
duration := f.Duration
|
||||
|
||||
if duration != 0 {
|
||||
if checksum := f.Fingerprints.GetString(file.FingerprintTypeMD5); checksum != "" {
|
||||
if checksum := f.Fingerprints.GetString(models.FingerprintTypeMD5); checksum != "" {
|
||||
fingerprint := graphql.FingerprintInput{
|
||||
Hash: checksum,
|
||||
Algorithm: graphql.FingerprintAlgorithmMd5,
|
||||
@@ -291,7 +289,7 @@ func (c Client) SubmitStashBoxFingerprints(ctx context.Context, sceneIDs []strin
|
||||
})
|
||||
}
|
||||
|
||||
if oshash := f.Fingerprints.GetString(file.FingerprintTypeOshash); oshash != "" {
|
||||
if oshash := f.Fingerprints.GetString(models.FingerprintTypeOshash); oshash != "" {
|
||||
fingerprint := graphql.FingerprintInput{
|
||||
Hash: oshash,
|
||||
Algorithm: graphql.FingerprintAlgorithmOshash,
|
||||
@@ -303,7 +301,7 @@ func (c Client) SubmitStashBoxFingerprints(ctx context.Context, sceneIDs []strin
|
||||
})
|
||||
}
|
||||
|
||||
if phash := f.Fingerprints.GetInt64(file.FingerprintTypePhash); phash != 0 {
|
||||
if phash := f.Fingerprints.GetInt64(models.FingerprintTypePhash); phash != 0 {
|
||||
fingerprint := graphql.FingerprintInput{
|
||||
Hash: utils.PhashToString(phash),
|
||||
Algorithm: graphql.FingerprintAlgorithmPhash,
|
||||
@@ -979,7 +977,7 @@ func (c Client) SubmitSceneDraft(ctx context.Context, scene *models.Scene, endpo
|
||||
duration := f.Duration
|
||||
|
||||
if duration != 0 {
|
||||
if oshash := f.Fingerprints.GetString(file.FingerprintTypeOshash); oshash != "" {
|
||||
if oshash := f.Fingerprints.GetString(models.FingerprintTypeOshash); oshash != "" {
|
||||
fingerprint := graphql.FingerprintInput{
|
||||
Hash: oshash,
|
||||
Algorithm: graphql.FingerprintAlgorithmOshash,
|
||||
@@ -988,7 +986,7 @@ func (c Client) SubmitSceneDraft(ctx context.Context, scene *models.Scene, endpo
|
||||
fingerprints = appendFingerprintUnique(fingerprints, &fingerprint)
|
||||
}
|
||||
|
||||
if checksum := f.Fingerprints.GetString(file.FingerprintTypeMD5); checksum != "" {
|
||||
if checksum := f.Fingerprints.GetString(models.FingerprintTypeMD5); checksum != "" {
|
||||
fingerprint := graphql.FingerprintInput{
|
||||
Hash: checksum,
|
||||
Algorithm: graphql.FingerprintAlgorithmMd5,
|
||||
@@ -997,7 +995,7 @@ func (c Client) SubmitSceneDraft(ctx context.Context, scene *models.Scene, endpo
|
||||
fingerprints = appendFingerprintUnique(fingerprints, &fingerprint)
|
||||
}
|
||||
|
||||
if phash := f.Fingerprints.GetInt64(file.FingerprintTypePhash); phash != 0 {
|
||||
if phash := f.Fingerprints.GetInt64(models.FingerprintTypePhash); phash != 0 {
|
||||
fingerprint := graphql.FingerprintInput{
|
||||
Hash: utils.PhashToString(phash),
|
||||
Algorithm: graphql.FingerprintAlgorithmPhash,
|
||||
|
||||
Reference in New Issue
Block a user