mirror of
https://github.com/stashapp/stash.git
synced 2025-12-06 16:34:02 +01:00
* 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
57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
package identify
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/stashapp/stash/pkg/models"
|
|
)
|
|
|
|
type PerformerCreator interface {
|
|
models.PerformerCreator
|
|
UpdateImage(ctx context.Context, performerID int, image []byte) error
|
|
}
|
|
|
|
func getPerformerID(ctx context.Context, endpoint string, w PerformerCreator, p *models.ScrapedPerformer, createMissing bool, skipSingleNamePerformers bool) (*int, error) {
|
|
if p.StoredID != nil {
|
|
// existing performer, just add it
|
|
performerID, err := strconv.Atoi(*p.StoredID)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error converting performer ID %s: %w", *p.StoredID, err)
|
|
}
|
|
|
|
return &performerID, nil
|
|
} else if createMissing && p.Name != nil { // name is mandatory
|
|
// skip single name performers with no disambiguation
|
|
if skipSingleNamePerformers && !strings.Contains(*p.Name, " ") && (p.Disambiguation == nil || len(*p.Disambiguation) == 0) {
|
|
return nil, ErrSkipSingleNamePerformer
|
|
}
|
|
return createMissingPerformer(ctx, endpoint, w, p)
|
|
}
|
|
|
|
return nil, nil
|
|
}
|
|
|
|
func createMissingPerformer(ctx context.Context, endpoint string, w PerformerCreator, p *models.ScrapedPerformer) (*int, error) {
|
|
newPerformer := p.ToPerformer(endpoint, nil)
|
|
performerImage, err := p.GetImage(ctx, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = w.Create(ctx, newPerformer)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error creating performer: %w", err)
|
|
}
|
|
|
|
// update image table
|
|
if len(performerImage) > 0 {
|
|
if err := w.UpdateImage(ctx, newPerformer.ID, performerImage); err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
return &newPerformer.ID, nil
|
|
}
|