Merge pull request #109 from WithoutPants/optional_performer_image
Generate performer checksum from name instead of image. Use default performer image
@@ -15,7 +15,7 @@ mutation PerformerCreate(
|
||||
$twitter: String,
|
||||
$instagram: String,
|
||||
$favorite: Boolean,
|
||||
$image: String!) {
|
||||
$image: String) {
|
||||
|
||||
performerCreate(input: {
|
||||
name: $name,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
mutation StudioCreate(
|
||||
$name: String!,
|
||||
$url: String,
|
||||
$image: String!) {
|
||||
$image: String) {
|
||||
|
||||
studioCreate(input: { name: $name, url: $url, image: $image }) {
|
||||
...StudioData
|
||||
|
||||
@@ -41,7 +41,7 @@ input PerformerCreateInput {
|
||||
instagram: String
|
||||
favorite: Boolean
|
||||
"""This should be base64 encoded"""
|
||||
image: String!
|
||||
image: String
|
||||
}
|
||||
|
||||
input PerformerUpdateInput {
|
||||
|
||||
@@ -12,7 +12,7 @@ input StudioCreateInput {
|
||||
name: String!
|
||||
url: String
|
||||
"""This should be base64 encoded"""
|
||||
image: String!
|
||||
image: String
|
||||
}
|
||||
|
||||
input StudioUpdateInput {
|
||||
|
||||
19
pkg/api/images.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
|
||||
"github.com/gobuffalo/packr/v2"
|
||||
)
|
||||
|
||||
var performerBox *packr.Box
|
||||
|
||||
func initialiseImages() {
|
||||
performerBox = packr.New("Performer Box", "../../static/performer")
|
||||
}
|
||||
|
||||
func getRandomPerformerImage() ([]byte, error) {
|
||||
imageFiles := performerBox.List()
|
||||
index := rand.Intn(len(imageFiles))
|
||||
return performerBox.Find(imageFiles[index])
|
||||
}
|
||||
@@ -3,16 +3,27 @@ package api
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/stashapp/stash/pkg/database"
|
||||
"github.com/stashapp/stash/pkg/models"
|
||||
"github.com/stashapp/stash/pkg/utils"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (r *mutationResolver) PerformerCreate(ctx context.Context, input models.PerformerCreateInput) (*models.Performer, error) {
|
||||
// Process the base 64 encoded image string
|
||||
checksum, imageData, err := utils.ProcessBase64Image(input.Image)
|
||||
// generate checksum from performer name rather than image
|
||||
checksum := utils.MD5FromString(*input.Name)
|
||||
|
||||
var imageData []byte
|
||||
var err error
|
||||
|
||||
if input.Image == nil {
|
||||
imageData, err = getRandomPerformerImage()
|
||||
} else {
|
||||
_, imageData, err = utils.ProcessBase64Image(*input.Image)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -101,15 +112,18 @@ func (r *mutationResolver) PerformerUpdate(ctx context.Context, input models.Per
|
||||
UpdatedAt: models.SQLiteTimestamp{Timestamp: time.Now()},
|
||||
}
|
||||
if input.Image != nil {
|
||||
checksum, imageData, err := utils.ProcessBase64Image(*input.Image)
|
||||
_, imageData, err := utils.ProcessBase64Image(*input.Image)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
updatedPerformer.Image = imageData
|
||||
updatedPerformer.Checksum = checksum
|
||||
}
|
||||
if input.Name != nil {
|
||||
// generate checksum from performer name rather than image
|
||||
checksum := utils.MD5FromString(*input.Name)
|
||||
|
||||
updatedPerformer.Name = sql.NullString{String: *input.Name, Valid: true}
|
||||
updatedPerformer.Checksum = checksum
|
||||
}
|
||||
if input.URL != nil {
|
||||
updatedPerformer.URL = sql.NullString{String: *input.URL, Valid: true}
|
||||
@@ -188,4 +202,3 @@ func (r *mutationResolver) PerformerDestroy(ctx context.Context, input models.Pe
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,18 @@ import (
|
||||
)
|
||||
|
||||
func (r *mutationResolver) StudioCreate(ctx context.Context, input models.StudioCreateInput) (*models.Studio, error) {
|
||||
// generate checksum from studio name rather than image
|
||||
checksum := utils.MD5FromString(input.Name)
|
||||
|
||||
var imageData []byte
|
||||
var err error
|
||||
|
||||
if input.Image == nil {
|
||||
input.Image = &models.DefaultStudioImage
|
||||
}
|
||||
|
||||
// Process the base 64 encoded image string
|
||||
checksum, imageData, err := utils.ProcessBase64Image(input.Image)
|
||||
_, imageData, err = utils.ProcessBase64Image(*input.Image)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -56,15 +66,17 @@ func (r *mutationResolver) StudioUpdate(ctx context.Context, input models.Studio
|
||||
UpdatedAt: models.SQLiteTimestamp{Timestamp: time.Now()},
|
||||
}
|
||||
if input.Image != nil {
|
||||
checksum, imageData, err := utils.ProcessBase64Image(*input.Image)
|
||||
_, imageData, err := utils.ProcessBase64Image(*input.Image)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
updatedStudio.Image = imageData
|
||||
updatedStudio.Checksum = checksum
|
||||
}
|
||||
if input.Name != nil {
|
||||
// generate checksum from studio name rather than image
|
||||
checksum := utils.MD5FromString(*input.Name)
|
||||
updatedStudio.Name = sql.NullString{String: *input.Name, Valid: true}
|
||||
updatedStudio.Checksum = checksum
|
||||
}
|
||||
if input.URL != nil {
|
||||
updatedStudio.URL = sql.NullString{String: *input.URL, Valid: true}
|
||||
|
||||
@@ -66,6 +66,8 @@ func Start() {
|
||||
//legacyUiBox = packr.New("UI Box", "../../ui/v1/dist/stash-frontend")
|
||||
setupUIBox = packr.New("Setup UI Box", "../../ui/setup")
|
||||
|
||||
initialiseImages()
|
||||
|
||||
r := chi.NewRouter()
|
||||
|
||||
r.Use(authenticateHandler())
|
||||
|
||||
@@ -64,8 +64,11 @@ func (t *ImportTask) ImportPerformers(ctx context.Context) {
|
||||
|
||||
logger.Progressf("[performers] %d of %d", index, len(t.Mappings.Performers))
|
||||
|
||||
// generate checksum from performer name rather than image
|
||||
checksum := utils.MD5FromString(performerJSON.Name)
|
||||
|
||||
// Process the base 64 encoded image string
|
||||
checksum, imageData, err := utils.ProcessBase64Image(performerJSON.Image)
|
||||
_, imageData, err := utils.ProcessBase64Image(performerJSON.Image)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
logger.Errorf("[performers] <%s> invalid image: %s", mappingJSON.Checksum, err.Error())
|
||||
@@ -159,8 +162,11 @@ func (t *ImportTask) ImportStudios(ctx context.Context) {
|
||||
|
||||
logger.Progressf("[studios] %d of %d", index, len(t.Mappings.Studios))
|
||||
|
||||
// generate checksum from studio name rather than image
|
||||
checksum := utils.MD5FromString(studioJSON.Name)
|
||||
|
||||
// Process the base 64 encoded image string
|
||||
checksum, imageData, err := utils.ProcessBase64Image(studioJSON.Image)
|
||||
_, imageData, err := utils.ProcessBase64Image(studioJSON.Image)
|
||||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
logger.Errorf("[studios] <%s> invalid image: %s", mappingJSON.Checksum, err.Error())
|
||||
|
||||
@@ -13,3 +13,5 @@ type Studio struct {
|
||||
CreatedAt SQLiteTimestamp `db:"created_at" json:"created_at"`
|
||||
UpdatedAt SQLiteTimestamp `db:"updated_at" json:"updated_at"`
|
||||
}
|
||||
|
||||
var DefaultStudioImage string = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4wgVBQsJl1CMZAAAASJJREFUeNrt3N0JwyAYhlEj3cj9R3Cm5rbkqtAP+qrnGaCYHPwJpLlaa++mmLpbAERAgAgIEAEBIiBABERAgAgIEAEBIiBABERAgAgIEAHZuVflj40x4i94zhk9vqsVvEq6AsQqMP1EjORx20OACAgQRRx7T+zzcFBxcjNDfoB4ntQqTm5Awo7MlqywZxcgYQ+RlqywJ3ozJAQCSBiEJSsQA0gYBpDAgAARECACAkRAgAgIEAERECACAmSjUv6eAOSB8m8YIGGzBUjYbAESBgMkbBkDEjZbgITBAClcxiqQvEoatreYIWEBASIgJ4Gkf11ntXH3nS9uxfGWfJ5J9hAgAgJEQAQEiIAAERAgAgJEQAQEiIAAERAgAgJEQAQEiL7qBuc6RKLHxr0CAAAAAElFTkSuQmCC"
|
||||
|
||||
@@ -12,6 +12,11 @@ func MD5FromBytes(data []byte) string {
|
||||
return fmt.Sprintf("%x", result)
|
||||
}
|
||||
|
||||
func MD5FromString(str string) string {
|
||||
data := []byte(str)
|
||||
return MD5FromBytes(data)
|
||||
}
|
||||
|
||||
func MD5FromFilePath(filePath string) (string, error) {
|
||||
f, err := os.Open(filePath)
|
||||
if err != nil {
|
||||
|
||||
BIN
static/performer/NoName01.png
Normal file
|
After Width: | Height: | Size: 52 KiB |
BIN
static/performer/NoName02.png
Normal file
|
After Width: | Height: | Size: 49 KiB |
BIN
static/performer/NoName03.png
Normal file
|
After Width: | Height: | Size: 49 KiB |
BIN
static/performer/NoName04.png
Normal file
|
After Width: | Height: | Size: 50 KiB |
BIN
static/performer/NoName05.png
Normal file
|
After Width: | Height: | Size: 48 KiB |
BIN
static/performer/NoName06.png
Normal file
|
After Width: | Height: | Size: 50 KiB |
BIN
static/performer/NoName07.png
Normal file
|
After Width: | Height: | Size: 46 KiB |
BIN
static/performer/NoName08.png
Normal file
|
After Width: | Height: | Size: 51 KiB |
BIN
static/performer/NoName09.png
Normal file
|
After Width: | Height: | Size: 47 KiB |
BIN
static/performer/NoName10.png
Normal file
|
After Width: | Height: | Size: 50 KiB |
BIN
static/performer/NoName11.png
Normal file
|
After Width: | Height: | Size: 49 KiB |
BIN
static/performer/NoName12.png
Normal file
|
After Width: | Height: | Size: 152 KiB |
BIN
static/performer/NoName13.png
Normal file
|
After Width: | Height: | Size: 43 KiB |
BIN
static/performer/NoName14.png
Normal file
|
After Width: | Height: | Size: 46 KiB |
BIN
static/performer/NoName15.png
Normal file
|
After Width: | Height: | Size: 52 KiB |
BIN
static/performer/NoName16.png
Normal file
|
After Width: | Height: | Size: 53 KiB |
BIN
static/performer/NoName17.png
Normal file
|
After Width: | Height: | Size: 50 KiB |
BIN
static/performer/NoName18.png
Normal file
|
After Width: | Height: | Size: 50 KiB |
BIN
static/performer/NoName19.png
Normal file
|
After Width: | Height: | Size: 50 KiB |
BIN
static/performer/NoName20.png
Normal file
|
After Width: | Height: | Size: 50 KiB |
BIN
static/performer/NoName21.png
Normal file
|
After Width: | Height: | Size: 47 KiB |
BIN
static/performer/NoName22.png
Normal file
|
After Width: | Height: | Size: 48 KiB |
BIN
static/performer/NoName23.png
Normal file
|
After Width: | Height: | Size: 50 KiB |
BIN
static/performer/NoName24.png
Normal file
|
After Width: | Height: | Size: 50 KiB |
BIN
static/performer/NoName25.png
Normal file
|
After Width: | Height: | Size: 49 KiB |
BIN
static/performer/NoName26.png
Normal file
|
After Width: | Height: | Size: 48 KiB |
BIN
static/performer/NoName27.png
Normal file
|
After Width: | Height: | Size: 49 KiB |
BIN
static/performer/NoName28.png
Normal file
|
After Width: | Height: | Size: 51 KiB |
BIN
static/performer/NoName29.png
Normal file
|
After Width: | Height: | Size: 49 KiB |
BIN
static/performer/NoName30.png
Normal file
|
After Width: | Height: | Size: 49 KiB |
BIN
static/performer/NoName31.png
Normal file
|
After Width: | Height: | Size: 48 KiB |
BIN
static/performer/NoName32.png
Normal file
|
After Width: | Height: | Size: 51 KiB |
BIN
static/performer/NoName33.png
Normal file
|
After Width: | Height: | Size: 50 KiB |
BIN
static/performer/NoName34.png
Normal file
|
After Width: | Height: | Size: 50 KiB |
BIN
static/performer/NoName35.png
Normal file
|
After Width: | Height: | Size: 46 KiB |
BIN
static/performer/NoName36.png
Normal file
|
After Width: | Height: | Size: 47 KiB |
BIN
static/performer/NoName37.png
Normal file
|
After Width: | Height: | Size: 48 KiB |
BIN
static/performer/NoName38.png
Normal file
|
After Width: | Height: | Size: 44 KiB |
BIN
static/performer/NoName39.png
Normal file
|
After Width: | Height: | Size: 48 KiB |
BIN
static/performer/NoName40.png
Normal file
|
After Width: | Height: | Size: 53 KiB |