Add random male performer image (#491)

* Add random male performer image during performer creation if gender is male
This commit is contained in:
bnkai 2020-04-25 02:54:42 +03:00 committed by GitHub
parent 5923917e6c
commit 5e84c0922d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 4 deletions

View File

@ -2,18 +2,31 @@ package api
import (
"math/rand"
"strings"
"github.com/gobuffalo/packr/v2"
)
var performerBox *packr.Box
var performerBoxMale *packr.Box
func initialiseImages() {
performerBox = packr.New("Performer Box", "../../static/performer")
performerBoxMale = packr.New("Male Performer Box", "../../static/performer_male")
}
func getRandomPerformerImage() ([]byte, error) {
imageFiles := performerBox.List()
func getRandomPerformerImage(gender string) ([]byte, error) {
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))
return performerBox.Find(imageFiles[index])
return box.Find(imageFiles[index])
}

View File

@ -19,7 +19,11 @@ func (r *mutationResolver) PerformerCreate(ctx context.Context, input models.Per
var err error
if input.Image == nil {
imageData, err = getRandomPerformerImage()
gender := ""
if input.Gender != nil {
gender = input.Gender.String()
}
imageData, err = getRandomPerformerImage(gender)
} else {
_, 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