mirror of
https://github.com/stashapp/stash.git
synced 2026-02-08 00:12:55 +01:00
Fix custom field import/export for studio
This commit is contained in:
parent
35cca73709
commit
08ba97bb8e
3 changed files with 24 additions and 5 deletions
|
|
@ -25,6 +25,8 @@ type Studio struct {
|
|||
Tags []string `json:"tags,omitempty"`
|
||||
IgnoreAutoTag bool `json:"ignore_auto_tag,omitempty"`
|
||||
|
||||
CustomFields map[string]interface{} `json:"custom_fields,omitempty"`
|
||||
|
||||
// deprecated - for import only
|
||||
URL string `json:"url,omitempty"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ type FinderImageStashIDGetter interface {
|
|||
models.URLLoader
|
||||
models.StashIDLoader
|
||||
GetImage(ctx context.Context, studioID int) ([]byte, error)
|
||||
models.CustomFieldsReader
|
||||
}
|
||||
|
||||
// ToJSON converts a Studio object into its JSON equivalent.
|
||||
|
|
@ -60,6 +61,12 @@ func ToJSON(ctx context.Context, reader FinderImageStashIDGetter, studio *models
|
|||
}
|
||||
newStudioJSON.StashIDs = studio.StashIDs.List()
|
||||
|
||||
var err error
|
||||
newStudioJSON.CustomFields, err = reader.GetCustomFields(ctx, studio.ID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("getting studio custom fields: %v", err)
|
||||
}
|
||||
|
||||
image, err := reader.GetImage(ctx, studio.ID)
|
||||
if err != nil {
|
||||
logger.Errorf("Error getting studio image: %v", err)
|
||||
|
|
|
|||
|
|
@ -26,13 +26,15 @@ type Importer struct {
|
|||
Input jsonschema.Studio
|
||||
MissingRefBehaviour models.ImportMissingRefEnum
|
||||
|
||||
ID int
|
||||
studio models.Studio
|
||||
imageData []byte
|
||||
ID int
|
||||
studio models.Studio
|
||||
customFields models.CustomFieldMap
|
||||
imageData []byte
|
||||
}
|
||||
|
||||
func (i *Importer) PreImport(ctx context.Context) error {
|
||||
i.studio = studioJSONtoStudio(i.Input)
|
||||
i.customFields = i.Input.CustomFields
|
||||
|
||||
if err := i.populateParentStudio(ctx); err != nil {
|
||||
return err
|
||||
|
|
@ -196,7 +198,10 @@ func (i *Importer) FindExistingID(ctx context.Context) (*int, error) {
|
|||
}
|
||||
|
||||
func (i *Importer) Create(ctx context.Context) (*int, error) {
|
||||
err := i.ReaderWriter.Create(ctx, &models.CreateStudioInput{Studio: &i.studio})
|
||||
err := i.ReaderWriter.Create(ctx, &models.CreateStudioInput{
|
||||
Studio: &i.studio,
|
||||
CustomFields: i.customFields,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating studio: %v", err)
|
||||
}
|
||||
|
|
@ -208,7 +213,12 @@ func (i *Importer) Create(ctx context.Context) (*int, error) {
|
|||
func (i *Importer) Update(ctx context.Context, id int) error {
|
||||
studio := i.studio
|
||||
studio.ID = id
|
||||
err := i.ReaderWriter.Update(ctx, &models.UpdateStudioInput{Studio: &studio})
|
||||
err := i.ReaderWriter.Update(ctx, &models.UpdateStudioInput{
|
||||
Studio: &studio,
|
||||
CustomFields: models.CustomFieldsInput{
|
||||
Full: i.customFields,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("error updating existing studio: %v", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue