Studio Tagger (#3510)

* Studio image and parent studio support in scene tagger
* Refactor studio backend and add studio tagger
---------
Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
Flashy78
2023-07-30 16:50:24 -07:00
committed by GitHub
parent d48dbeb864
commit a665a56ef0
79 changed files with 5224 additions and 1039 deletions

View File

@@ -14,8 +14,6 @@ type NameFinderCreatorUpdater interface {
NameFinderCreator
Update(ctx context.Context, updatedStudio *models.Studio) error
UpdateImage(ctx context.Context, studioID int, image []byte) error
UpdateAliases(ctx context.Context, studioID int, aliases []string) error
UpdateStashIDs(ctx context.Context, studioID int, stashIDs []models.StashID) error
}
var ErrParentStudioNotExist = errors.New("parent studio does not exist")
@@ -25,20 +23,13 @@ type Importer struct {
Input jsonschema.Studio
MissingRefBehaviour models.ImportMissingRefEnum
ID int
studio models.Studio
imageData []byte
}
func (i *Importer) PreImport(ctx context.Context) error {
i.studio = models.Studio{
Name: i.Input.Name,
URL: i.Input.URL,
Details: i.Input.Details,
IgnoreAutoTag: i.Input.IgnoreAutoTag,
CreatedAt: i.Input.CreatedAt.GetTime(),
UpdatedAt: i.Input.UpdatedAt.GetTime(),
Rating: &i.Input.Rating,
}
i.studio = studioJSONtoStudio(i.Input)
if err := i.populateParentStudio(ctx); err != nil {
return err
@@ -87,7 +78,9 @@ func (i *Importer) populateParentStudio(ctx context.Context) error {
}
func (i *Importer) createParentStudio(ctx context.Context, name string) (int, error) {
newStudio := models.NewStudio(name)
newStudio := &models.Studio{
Name: name,
}
err := i.ReaderWriter.Create(ctx, newStudio)
if err != nil {
@@ -104,16 +97,6 @@ func (i *Importer) PostImport(ctx context.Context, id int) error {
}
}
if len(i.Input.StashIDs) > 0 {
if err := i.ReaderWriter.UpdateStashIDs(ctx, id, i.Input.StashIDs); err != nil {
return fmt.Errorf("error setting stash id: %v", err)
}
}
if err := i.ReaderWriter.UpdateAliases(ctx, id, i.Input.Aliases); err != nil {
return fmt.Errorf("error setting tag aliases: %v", err)
}
return nil
}
@@ -156,3 +139,23 @@ func (i *Importer) Update(ctx context.Context, id int) error {
return nil
}
func studioJSONtoStudio(studioJSON jsonschema.Studio) models.Studio {
newStudio := models.Studio{
Name: studioJSON.Name,
URL: studioJSON.URL,
Aliases: models.NewRelatedStrings(studioJSON.Aliases),
Details: studioJSON.Details,
IgnoreAutoTag: studioJSON.IgnoreAutoTag,
CreatedAt: studioJSON.CreatedAt.GetTime(),
UpdatedAt: studioJSON.UpdatedAt.GetTime(),
StashIDs: models.NewRelatedStashIDs(studioJSON.StashIDs),
}
if studioJSON.Rating != 0 {
newStudio.Rating = &studioJSON.Rating
}
return newStudio
}