Performer disambiguation and aliases (#3113)

* Refactor performer relationships
* Remove checksum from performer
* Add disambiguation, overhaul aliases
* Add disambiguation filter criterion
* Improve name matching during import
* Add disambiguation filtering in UI
* Include aliases in performer select
This commit is contained in:
WithoutPants
2022-12-01 13:54:08 +11:00
committed by GitHub
parent d2395e579c
commit 4daf0a14a2
72 changed files with 2283 additions and 993 deletions

View File

@@ -11,34 +11,35 @@ import (
"github.com/stashapp/stash/pkg/utils"
)
type ImageStashIDGetter interface {
type ImageAliasStashIDGetter interface {
GetImage(ctx context.Context, performerID int) ([]byte, error)
models.AliasLoader
models.StashIDLoader
}
// ToJSON converts a Performer object into its JSON equivalent.
func ToJSON(ctx context.Context, reader ImageStashIDGetter, performer *models.Performer) (*jsonschema.Performer, error) {
func ToJSON(ctx context.Context, reader ImageAliasStashIDGetter, performer *models.Performer) (*jsonschema.Performer, error) {
newPerformerJSON := jsonschema.Performer{
Name: performer.Name,
Gender: performer.Gender.String(),
URL: performer.URL,
Ethnicity: performer.Ethnicity,
Country: performer.Country,
EyeColor: performer.EyeColor,
Measurements: performer.Measurements,
FakeTits: performer.FakeTits,
CareerLength: performer.CareerLength,
Tattoos: performer.Tattoos,
Piercings: performer.Piercings,
Aliases: performer.Aliases,
Twitter: performer.Twitter,
Instagram: performer.Instagram,
Favorite: performer.Favorite,
Details: performer.Details,
HairColor: performer.HairColor,
IgnoreAutoTag: performer.IgnoreAutoTag,
CreatedAt: json.JSONTime{Time: performer.CreatedAt},
UpdatedAt: json.JSONTime{Time: performer.UpdatedAt},
Name: performer.Name,
Disambiguation: performer.Disambiguation,
Gender: performer.Gender.String(),
URL: performer.URL,
Ethnicity: performer.Ethnicity,
Country: performer.Country,
EyeColor: performer.EyeColor,
Measurements: performer.Measurements,
FakeTits: performer.FakeTits,
CareerLength: performer.CareerLength,
Tattoos: performer.Tattoos,
Piercings: performer.Piercings,
Twitter: performer.Twitter,
Instagram: performer.Instagram,
Favorite: performer.Favorite,
Details: performer.Details,
HairColor: performer.HairColor,
IgnoreAutoTag: performer.IgnoreAutoTag,
CreatedAt: json.JSONTime{Time: performer.CreatedAt},
UpdatedAt: json.JSONTime{Time: performer.UpdatedAt},
}
if performer.Birthdate != nil {
@@ -59,27 +60,27 @@ func ToJSON(ctx context.Context, reader ImageStashIDGetter, performer *models.Pe
newPerformerJSON.Weight = *performer.Weight
}
if err := performer.LoadAliases(ctx, reader); err != nil {
return nil, fmt.Errorf("loading performer aliases: %w", err)
}
newPerformerJSON.Aliases = performer.Aliases.List()
if err := performer.LoadStashIDs(ctx, reader); err != nil {
return nil, fmt.Errorf("loading performer stash ids: %w", err)
}
newPerformerJSON.StashIDs = performer.StashIDs.List()
image, err := reader.GetImage(ctx, performer.ID)
if err != nil {
return nil, fmt.Errorf("error getting performers image: %v", err)
return nil, fmt.Errorf("getting performers image: %w", err)
}
if len(image) > 0 {
newPerformerJSON.Image = utils.GetBase64StringFromData(image)
}
stashIDs, _ := reader.GetStashIDs(ctx, performer.ID)
var ret []models.StashID
for _, stashID := range stashIDs {
newJoin := models.StashID{
StashID: stashID.StashID,
Endpoint: stashID.Endpoint,
}
ret = append(ret, newJoin)
}
newPerformerJSON.StashIDs = ret
return &newPerformerJSON, nil
}