mirror of https://github.com/stashapp/stash.git
Add random male performer image (#491)
* Add random male performer image during performer creation if gender is male
This commit is contained in:
parent
5923917e6c
commit
5e84c0922d
|
@ -2,18 +2,31 @@ package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/gobuffalo/packr/v2"
|
"github.com/gobuffalo/packr/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var performerBox *packr.Box
|
var performerBox *packr.Box
|
||||||
|
var performerBoxMale *packr.Box
|
||||||
|
|
||||||
func initialiseImages() {
|
func initialiseImages() {
|
||||||
performerBox = packr.New("Performer Box", "../../static/performer")
|
performerBox = packr.New("Performer Box", "../../static/performer")
|
||||||
|
performerBoxMale = packr.New("Male Performer Box", "../../static/performer_male")
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRandomPerformerImage() ([]byte, error) {
|
func getRandomPerformerImage(gender string) ([]byte, error) {
|
||||||
imageFiles := performerBox.List()
|
var box *packr.Box
|
||||||
|
switch strings.ToUpper(gender) {
|
||||||
|
case "FEMALE":
|
||||||
|
box = performerBox
|
||||||
|
case "MALE":
|
||||||
|
box = performerBoxMale
|
||||||
|
default:
|
||||||
|
box = performerBox
|
||||||
|
|
||||||
|
}
|
||||||
|
imageFiles := box.List()
|
||||||
index := rand.Intn(len(imageFiles))
|
index := rand.Intn(len(imageFiles))
|
||||||
return performerBox.Find(imageFiles[index])
|
return box.Find(imageFiles[index])
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,11 @@ func (r *mutationResolver) PerformerCreate(ctx context.Context, input models.Per
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if input.Image == nil {
|
if input.Image == nil {
|
||||||
imageData, err = getRandomPerformerImage()
|
gender := ""
|
||||||
|
if input.Gender != nil {
|
||||||
|
gender = input.Gender.String()
|
||||||
|
}
|
||||||
|
imageData, err = getRandomPerformerImage(gender)
|
||||||
} else {
|
} else {
|
||||||
_, imageData, err = utils.ProcessBase64Image(*input.Image)
|
_, imageData, err = utils.ProcessBase64Image(*input.Image)
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 27 KiB |
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
Loading…
Reference in New Issue