mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
Feature: Support Multiple URLs in Studios (#6223)
* Backend support for studio URLs * FrontEnd addition * Support URLs in BulkStudioUpdate * Update tagger modal for URLs --------- Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
@@ -33,7 +33,6 @@ func (r *mutationResolver) StudioCreate(ctx context.Context, input models.Studio
|
||||
newStudio := models.NewStudio()
|
||||
|
||||
newStudio.Name = input.Name
|
||||
newStudio.URL = translator.string(input.URL)
|
||||
newStudio.Rating = input.Rating100
|
||||
newStudio.Favorite = translator.bool(input.Favorite)
|
||||
newStudio.Details = translator.string(input.Details)
|
||||
@@ -43,6 +42,15 @@ func (r *mutationResolver) StudioCreate(ctx context.Context, input models.Studio
|
||||
|
||||
var err error
|
||||
|
||||
newStudio.URLs = models.NewRelatedStrings([]string{})
|
||||
if input.URL != nil {
|
||||
newStudio.URLs.Add(*input.URL)
|
||||
}
|
||||
|
||||
if input.Urls != nil {
|
||||
newStudio.URLs.Add(input.Urls...)
|
||||
}
|
||||
|
||||
newStudio.ParentID, err = translator.intPtrFromString(input.ParentID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("converting parent id: %w", err)
|
||||
@@ -106,7 +114,6 @@ func (r *mutationResolver) StudioUpdate(ctx context.Context, input models.Studio
|
||||
|
||||
updatedStudio.ID = studioID
|
||||
updatedStudio.Name = translator.optionalString(input.Name, "name")
|
||||
updatedStudio.URL = translator.optionalString(input.URL, "url")
|
||||
updatedStudio.Details = translator.optionalString(input.Details, "details")
|
||||
updatedStudio.Rating = translator.optionalInt(input.Rating100, "rating100")
|
||||
updatedStudio.Favorite = translator.optionalBool(input.Favorite, "favorite")
|
||||
@@ -124,6 +131,26 @@ func (r *mutationResolver) StudioUpdate(ctx context.Context, input models.Studio
|
||||
return nil, fmt.Errorf("converting tag ids: %w", err)
|
||||
}
|
||||
|
||||
if translator.hasField("urls") {
|
||||
// ensure url not included in the input
|
||||
if err := r.validateNoLegacyURLs(translator); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
updatedStudio.URLs = translator.updateStrings(input.Urls, "urls")
|
||||
} else if translator.hasField("url") {
|
||||
// handle legacy url field
|
||||
legacyURLs := []string{}
|
||||
if input.URL != nil {
|
||||
legacyURLs = append(legacyURLs, *input.URL)
|
||||
}
|
||||
|
||||
updatedStudio.URLs = &models.UpdateStrings{
|
||||
Mode: models.RelationshipUpdateModeSet,
|
||||
Values: legacyURLs,
|
||||
}
|
||||
}
|
||||
|
||||
// Process the base 64 encoded image string
|
||||
var imageData []byte
|
||||
imageIncluded := translator.hasField("image")
|
||||
@@ -181,7 +208,26 @@ func (r *mutationResolver) BulkStudioUpdate(ctx context.Context, input BulkStudi
|
||||
return nil, fmt.Errorf("converting parent id: %w", err)
|
||||
}
|
||||
|
||||
partial.URL = translator.optionalString(input.URL, "url")
|
||||
if translator.hasField("urls") {
|
||||
// ensure url/twitter/instagram are not included in the input
|
||||
if err := r.validateNoLegacyURLs(translator); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
partial.URLs = translator.updateStringsBulk(input.Urls, "urls")
|
||||
} else if translator.hasField("url") {
|
||||
// handle legacy url field
|
||||
legacyURLs := []string{}
|
||||
if input.URL != nil {
|
||||
legacyURLs = append(legacyURLs, *input.URL)
|
||||
}
|
||||
|
||||
partial.URLs = &models.UpdateStrings{
|
||||
Mode: models.RelationshipUpdateModeSet,
|
||||
Values: legacyURLs,
|
||||
}
|
||||
}
|
||||
|
||||
partial.Favorite = translator.optionalBool(input.Favorite, "favorite")
|
||||
partial.Rating = translator.optionalInt(input.Rating100, "rating100")
|
||||
partial.Details = translator.optionalString(input.Details, "details")
|
||||
|
||||
Reference in New Issue
Block a user