mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
Refactor stashbox package (#5699)
* Move stashbox package under pkg * Remove StashBox from method names * Add fingerprint conversion methods to Fingerprint Refactor Fingerprints methods * Make FindSceneByFingerprints accept fingerprints not scene ids * Refactor SubmitSceneDraft to not require readers * Have SubmitFingerprints accept scenes Remove SceneReader dependency * Move ScrapedScene to models package * Move ScrapedImage into models package * Move ScrapedGallery into models package * Move Scene relationship matching out of stashbox package This is now expected to be done in the client code * Remove TagFinder dependency from stashbox.Client * Make stashbox scene find full hierarchy of studios * Move studio resolution into separate method * Move studio matching out of stashbox package This is now client code responsibility * Move performer matching out of FindPerformerByID and FindPerformerByName * Refactor performer querying logic and remove unused stashbox models Renames FindStashBoxPerformersByPerformerNames to QueryPerformers and accepts names instead of performer ids * Refactor SubmitPerformerDraft to not load relationships This will be the responsibility of the calling code * Remove repository references
This commit is contained in:
@@ -20,18 +20,52 @@ type GroupNamesFinder interface {
|
||||
FindByNames(ctx context.Context, names []string, nocase bool) ([]*models.Group, error)
|
||||
}
|
||||
|
||||
type SceneRelationships struct {
|
||||
PerformerFinder PerformerFinder
|
||||
TagFinder models.TagQueryer
|
||||
StudioFinder StudioFinder
|
||||
}
|
||||
|
||||
// MatchRelationships accepts a scraped scene and attempts to match its relationships to existing stash models.
|
||||
func (r SceneRelationships) MatchRelationships(ctx context.Context, s *models.ScrapedScene, endpoint string) error {
|
||||
thisStudio := s.Studio
|
||||
for thisStudio != nil {
|
||||
if err := ScrapedStudio(ctx, r.StudioFinder, s.Studio, endpoint); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
thisStudio = thisStudio.Parent
|
||||
}
|
||||
|
||||
for _, p := range s.Performers {
|
||||
err := ScrapedPerformer(ctx, r.PerformerFinder, p, endpoint)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for _, t := range s.Tags {
|
||||
err := ScrapedTag(ctx, r.TagFinder, t)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ScrapedPerformer matches the provided performer with the
|
||||
// performers in the database and sets the ID field if one is found.
|
||||
func ScrapedPerformer(ctx context.Context, qb PerformerFinder, p *models.ScrapedPerformer, stashBoxEndpoint *string) error {
|
||||
func ScrapedPerformer(ctx context.Context, qb PerformerFinder, p *models.ScrapedPerformer, stashBoxEndpoint string) error {
|
||||
if p.StoredID != nil || p.Name == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Check if a performer with the StashID already exists
|
||||
if stashBoxEndpoint != nil && p.RemoteSiteID != nil {
|
||||
if stashBoxEndpoint != "" && p.RemoteSiteID != nil {
|
||||
performers, err := qb.FindByStashID(ctx, models.StashID{
|
||||
StashID: *p.RemoteSiteID,
|
||||
Endpoint: *stashBoxEndpoint,
|
||||
Endpoint: stashBoxEndpoint,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -73,16 +107,16 @@ type StudioFinder interface {
|
||||
|
||||
// ScrapedStudio matches the provided studio with the studios
|
||||
// in the database and sets the ID field if one is found.
|
||||
func ScrapedStudio(ctx context.Context, qb StudioFinder, s *models.ScrapedStudio, stashBoxEndpoint *string) error {
|
||||
func ScrapedStudio(ctx context.Context, qb StudioFinder, s *models.ScrapedStudio, stashBoxEndpoint string) error {
|
||||
if s.StoredID != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Check if a studio with the StashID already exists
|
||||
if stashBoxEndpoint != nil && s.RemoteSiteID != nil {
|
||||
if stashBoxEndpoint != "" && s.RemoteSiteID != nil {
|
||||
studios, err := qb.FindByStashID(ctx, models.StashID{
|
||||
StashID: *s.RemoteSiteID,
|
||||
Endpoint: *stashBoxEndpoint,
|
||||
Endpoint: stashBoxEndpoint,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -118,6 +152,19 @@ func ScrapedStudio(ctx context.Context, qb StudioFinder, s *models.ScrapedStudio
|
||||
return nil
|
||||
}
|
||||
|
||||
// ScrapedStudioHierarchy executes ScrapedStudio for the provided studio and its parents recursively.
|
||||
func ScrapedStudioHierarchy(ctx context.Context, qb StudioFinder, s *models.ScrapedStudio, stashBoxEndpoint string) error {
|
||||
if err := ScrapedStudio(ctx, qb, s, stashBoxEndpoint); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if s.Parent == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return ScrapedStudioHierarchy(ctx, qb, s.Parent, stashBoxEndpoint)
|
||||
}
|
||||
|
||||
// ScrapedGroup matches the provided movie with the movies
|
||||
// in the database and returns the ID field if one is found.
|
||||
func ScrapedGroup(ctx context.Context, qb GroupNamesFinder, storedID *string, name *string) (matchedID *string, err error) {
|
||||
|
||||
Reference in New Issue
Block a user